Skip to content

Commit ce38a39

Browse files
authored
Merge branch 'master' into data-subsystem
2 parents 3ba9252 + 40b80be commit ce38a39

File tree

2 files changed

+64
-20
lines changed

2 files changed

+64
-20
lines changed

docs-site/content/docs/processing/task.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ top = false
1515
flair =[]
1616
+++
1717

18-
Tasks in `Loco` serve as ad-hoc functionalities to handle specific aspects of your application. Whether you need to fix data, send emails, delete a user, or update a customer order, creating a dedicated task for each scenario provides a flexible and efficient solution. While tasks require manual execution, the investment is worthwhile for several reasons:
18+
Tasks in `Loco` serve as ad-hoc functionalities to handle specific aspects of your application. Whether you need to fix data, send emails, delete a user, or update a customer order, creating a dedicated task for each scenario provides a flexible and efficient solution. You can run tasks manually or by [scheduling the task](@/docs/processing/scheduler.md).
1919

20+
Creating tasks is worthwhile for several reasons:
2021
- **Automation of Manual Work:** Tasks automate manual processes, streamlining repetitive actions.
2122
- **Utilization of Familiar Components:** Leverage your app's models, libraries, and existing logic within tasks.
2223
- **Elimination of UI Development:** Tasks don't require building user interfaces, focusing solely on backend operations.
@@ -56,6 +57,23 @@ cargo loco task <TASK_NAME>
5657
```
5758
<!-- </snip> -->
5859

60+
### Running a Task with Parameters
61+
62+
To pass parameters to a task, add a list of key:value to the command
63+
```sh
64+
[PARAMS]... Task params (e.g. <`my_task`> foo:bar baz:qux)`
65+
```
66+
```sh
67+
cargo loco task <TASK_NAME> [PARAMS]...
68+
```
69+
70+
Then use that value using [`cli_arg`](https://docs.rs/loco-rs/latest/loco_rs/task/struct.Vars.html#method.cli_arg) in the `run` method of the task
71+
```rust
72+
async fn run(&self, app_context: &AppContext, vars: &task::Vars) -> Result<()> {
73+
let foo = vars.cli_arg("foo");
74+
Ok(())
75+
}
76+
```
5977

6078
## Listing All Tasks
6179

src/schema.rs

+45-19
Original file line numberDiff line numberDiff line change
@@ -62,77 +62,78 @@ pub enum ColType {
6262
PkAuto,
6363
PkUuid,
6464
CharLen(u32),
65+
CharLenWithDefault(u32, char),
6566
CharLenNull(u32),
6667
CharLenUniq(u32),
6768
Char,
69+
CharWithDefault(char),
6870
CharNull,
6971
CharUniq,
7072
StringLen(u32),
73+
StringLenWithDefault(u32, String),
7174
StringLenNull(u32),
7275
StringLenUniq(u32),
7376
String,
77+
StringWithDefault(String),
7478
StringNull,
7579
StringUniq,
7680
Text,
81+
TextWithDefault(String),
7782
TextNull,
7883
TextUniq,
7984
Integer,
85+
IntegerWithDefault(i32),
8086
IntegerNull,
8187
IntegerUniq,
8288
Unsigned,
89+
UnsignedWithDefault(u32),
8390
UnsignedNull,
8491
UnsignedUniq,
85-
// Tiny fields are not supported due to differences in data types between PostgreSQL and SQLite:
86-
// * Postgres: i16
87-
// * Sqlite: i8
88-
// TinyUnsigned,
89-
// TinyUnsignedNull,
90-
// TinyUnsignedUniq,
9192
SmallUnsigned,
93+
SmallUnsignedWithDefault(u16),
9294
SmallUnsignedNull,
9395
SmallUnsignedUniq,
9496
BigUnsigned,
97+
BigUnsignedWithDefault(u64),
9598
BigUnsignedNull,
9699
BigUnsignedUniq,
97-
// Tiny fields are not supported due to differences in data types between PostgreSQL and SQLite:
98-
// * Postgres: i16
99-
// * Sqlite: i8
100-
// TinyInteger,
101-
// TinyIntegerNull,
102-
// TinyIntegerUniq,
103100
SmallInteger,
101+
SmallIntegerWithDefault(i16),
104102
SmallIntegerNull,
105103
SmallIntegerUniq,
106104
BigInteger,
105+
BigIntegerWithDefault(i64),
107106
BigIntegerNull,
108107
BigIntegerUniq,
109108
Decimal,
109+
DecimalWithDefault(f64),
110110
DecimalNull,
111111
DecimalUniq,
112112
DecimalLen(u32, u32),
113+
DecimalLenWithDefault(u32, u32, f64),
113114
DecimalLenNull(u32, u32),
114115
DecimalLenUniq(u32, u32),
115116
Float,
117+
FloatWithDefault(f32),
116118
FloatNull,
117119
FloatUniq,
118120
Double,
121+
DoubleWithDefault(f64),
119122
DoubleNull,
120123
DoubleUniq,
121124
Boolean,
125+
BooleanWithDefault(bool),
122126
BooleanNull,
123-
// Timestamp fields are not supported due to differences in data types between PostgreSQL and SQLite:
124-
// * Postgres: DateTime
125-
// * Sqlite: DateTimeUtc
126-
// Timestamp,
127-
// TimestampNull,
128-
// TimestampUniq,
129127
Date,
128+
DateWithDefault(String),
130129
DateNull,
131130
DateUniq,
132131
DateTime,
132+
DateTimeWithDefault(String),
133133
DateTimeNull,
134134
DateTimeUniq,
135135
Time,
136+
TimeWithDefault(String),
136137
TimeNull,
137138
TimeUniq,
138139
Interval(Option<PgInterval>, Option<u32>),
@@ -147,8 +148,8 @@ pub enum ColType {
147148
VarBinary(u32),
148149
VarBinaryNull(u32),
149150
VarBinaryUniq(u32),
150-
// Added variants based on the JSON
151151
TimestampWithTimeZone,
152+
TimestampWithTimeZoneWithDefault(String),
152153
TimestampWithTimeZoneNull,
153154
Json,
154155
JsonNull,
@@ -160,6 +161,7 @@ pub enum ColType {
160161
BlobNull,
161162
BlobUniq,
162163
Money,
164+
MoneyWithDefault(f64),
163165
MoneyNull,
164166
MoneyUniq,
165167
Uuid,
@@ -317,6 +319,30 @@ impl ColType {
317319
Self::Array(kind) => array(name, kind.clone()),
318320
Self::ArrayNull(kind) => array_null(name, kind.clone()),
319321
Self::ArrayUniq(kind) => array_uniq(name, kind.clone()),
322+
// defaults
323+
Self::MoneyWithDefault(v) => money(name).default(*v).take(),
324+
Self::IntegerWithDefault(v) => integer(name).default(*v).take(),
325+
Self::UnsignedWithDefault(v) => unsigned(name).default(*v).take(),
326+
Self::SmallUnsignedWithDefault(v) => small_unsigned(name).default(*v).take(),
327+
Self::BigUnsignedWithDefault(v) => big_unsigned(name).default(*v).take(),
328+
Self::SmallIntegerWithDefault(v) => small_integer(name).default(*v).take(),
329+
Self::BigIntegerWithDefault(v) => big_integer(name).default(*v).take(),
330+
Self::DecimalWithDefault(v) => decimal(name).default(*v).take(),
331+
Self::DecimalLenWithDefault(p, s, v) => decimal_len(name, *p, *s).default(*v).take(),
332+
Self::FloatWithDefault(v) => float(name).default(*v).take(),
333+
Self::DoubleWithDefault(v) => double(name).default(*v).take(),
334+
Self::BooleanWithDefault(v) => boolean(name).default(*v).take(),
335+
Self::DateWithDefault(v) => date(name).default(v.clone()).take(),
336+
Self::DateTimeWithDefault(v) => date_time(name).default(v.clone()).take(),
337+
Self::TimeWithDefault(v) => time(name).default(v.clone()).take(),
338+
Self::TimestampWithTimeZoneWithDefault(v) => {
339+
timestamptz(name).default(v.clone()).take()
340+
}
341+
Self::CharWithDefault(v) => char(name).default(*v).take(),
342+
Self::CharLenWithDefault(len, v) => char_len(name, *len).default(*v).take(),
343+
Self::StringWithDefault(v) => string(name).default(v.clone()).take(),
344+
Self::StringLenWithDefault(len, v) => string_len(name, *len).default(v.clone()).take(),
345+
Self::TextWithDefault(v) => text(name).default(v.clone()).take(),
320346
}
321347
}
322348
}

0 commit comments

Comments
 (0)