Skip to content

Commit 9c37a3a

Browse files
committed
Support jiff
1 parent d36fd4e commit 9c37a3a

32 files changed

Lines changed: 1816 additions & 588 deletions

File tree

.github/workflows/rust.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ jobs:
155155
kind: build
156156
- label: tokio native-tls mysql
157157
kind: test
158-
features: sqlx-mysql,runtime-tokio-native-tls
158+
features: sqlx-mysql,runtime-tokio-native-tls,unimplemented-jiff-sqlx-mysql
159159
- label: tokio rustls mysql
160160
kind: test
161-
features: sqlx-mysql,runtime-tokio-rustls
161+
features: sqlx-mysql,runtime-tokio-rustls,unimplemented-jiff-sqlx-mysql
162162
- label: tokio native-tls postgres
163163
kind: test
164164
features: sqlx-postgres,runtime-tokio-native-tls
@@ -417,8 +417,8 @@ jobs:
417417
~/.cargo/git/db/
418418
key: ${{ runner.os }}-cargo-mysql-tests-${{ hashFiles('**/Cargo.toml') }}
419419
- uses: mozilla-actions/sccache-action@v0.0.9
420-
- run: cargo test --test '*' --features tests-features,sqlx-mysql,runtime-${{ matrix.runtime }}-${{ matrix.tls }} --no-run
421-
- run: cargo test --test '*' --features tests-features,sqlx-mysql,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
420+
- run: cargo test --test '*' --features tests-features,sqlx-mysql,runtime-${{ matrix.runtime }}-${{ matrix.tls }},unimplemented-jiff-sqlx-mysql --no-run
421+
- run: cargo test --test '*' --features tests-features,sqlx-mysql,runtime-${{ matrix.runtime }}-${{ matrix.tls }},unimplemented-jiff-sqlx-mysql
422422
- run: cargo test --manifest-path sea-orm-migration/Cargo.toml --test '*' --features sqlx-mysql,runtime-${{ matrix.runtime }}-${{ matrix.tls }} --no-run
423423
- run: cargo test --manifest-path sea-orm-migration/Cargo.toml --test '*' --features sqlx-mysql,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
424424

@@ -470,8 +470,8 @@ jobs:
470470
~/.cargo/git/db/
471471
key: ${{ runner.os }}-cargo-mariadb-tests-${{ hashFiles('**/Cargo.toml') }}
472472
- uses: mozilla-actions/sccache-action@v0.0.9
473-
- run: cargo test --test '*' --features tests-features,sqlx-mysql,runtime-${{ matrix.runtime }}-${{ matrix.tls }} --no-run
474-
- run: cargo test --test '*' --features tests-features,sqlx-mysql,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
473+
- run: cargo test --test '*' --features tests-features,sqlx-mysql,runtime-${{ matrix.runtime }}-${{ matrix.tls }},unimplemented-jiff-sqlx-mysql --no-run
474+
- run: cargo test --test '*' --features tests-features,sqlx-mysql,runtime-${{ matrix.runtime }}-${{ matrix.tls }},unimplemented-jiff-sqlx-mysql
475475

476476
postgres:
477477
name: Postgres

Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ futures-util = { version = "0.3", default-features = false, features = [
5050
inventory = { version = "0.3", optional = true }
5151
ipnetwork = { version = "0.20", default-features = false, optional = true }
5252
itertools = "0.14.0"
53+
jiff = { version = "0.2.15", default-features = false, optional = true, features = [
54+
"std",
55+
"perf-inline",
56+
] }
57+
jiff-sqlx = { version = "0.1.1", default-features = false, optional = true }
5358
log = { version = "0.4", default-features = false }
5459
mac_address = { version = "1.1", default-features = false, optional = true }
5560
ouroboros = { version = "0.18", default-features = false }
@@ -98,6 +103,7 @@ sea-orm = { path = ".", features = [
98103
"mock",
99104
"postgres-array",
100105
"tests-cfg",
106+
"with-jiff",
101107
] }
102108
smol = { version = "1.2" }
103109
smol-potat = { version = "1.1" }
@@ -165,12 +171,14 @@ sqlx-mysql = [
165171
sqlx-postgres = [
166172
"sqlx-dep",
167173
"sea-query-sqlx/sqlx-postgres",
174+
"jiff-sqlx?/postgres",
168175
"postgres-array",
169176
"sea-schema?/sqlx-postgres",
170177
]
171178
sqlx-sqlite = [
172179
"sqlx-dep",
173180
"sea-query-sqlx/sqlx-sqlite",
181+
"jiff-sqlx?/sqlite",
174182
"sea-schema?/sqlx-sqlite",
175183
]
176184
sync = []
@@ -182,9 +190,13 @@ tests-features = [
182190
"schema-sync",
183191
"with-arrow",
184192
"with-bigdecimal",
193+
"with-jiff",
185194
"with-ipnetwork",
186195
]
187196
tracing-spans = []
197+
unimplemented-jiff-sqlx-mysql = [
198+
"sea-query-sqlx?/unimplemented-jiff-sqlx-mysql",
199+
]
188200
with-arrow = ["sea-orm-arrow", "sea-orm-macros/with-arrow"]
189201
with-bigdecimal = [
190202
"bigdecimal",
@@ -203,11 +215,18 @@ with-ipnetwork = [
203215
"sea-query/with-ipnetwork",
204216
"sea-query-sqlx?/with-ipnetwork",
205217
]
218+
with-jiff = [
219+
"jiff",
220+
"jiff-sqlx",
221+
"sea-query/with-jiff",
222+
"sea-query-sqlx?/with-jiff",
223+
]
206224
with-json = [
207225
"serde_json",
208226
"sea-query/with-json",
209227
"sea-orm-macros/with-json",
210228
"chrono?/serde",
229+
"jiff?/serde",
211230
"rust_decimal?/serde",
212231
"bigdecimal?/serde",
213232
"uuid?/serde",

sea-orm-cli/src/cli.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ pub enum DateTimeCrate {
399399
#[default]
400400
Chrono,
401401
Time,
402+
Jiff,
402403
}
403404

404405
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum, Default)]

sea-orm-cli/src/commands/generate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ impl From<DateTimeCrate> for CodegenDateTimeCrate {
360360
match date_time_crate {
361361
DateTimeCrate::Chrono => CodegenDateTimeCrate::Chrono,
362362
DateTimeCrate::Time => CodegenDateTimeCrate::Time,
363+
DateTimeCrate::Jiff => CodegenDateTimeCrate::Jiff,
363364
}
364365
}
365366
}

sea-orm-codegen/src/entity/column.rs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,27 @@ impl Column {
6060
ColumnType::Date => match opt.date_time_crate {
6161
DateTimeCrate::Chrono => "Date".to_owned(),
6262
DateTimeCrate::Time => "TimeDate".to_owned(),
63+
DateTimeCrate::Jiff => "JiffDate".to_owned(),
6364
},
6465
ColumnType::Time => match opt.date_time_crate {
6566
DateTimeCrate::Chrono => "Time".to_owned(),
6667
DateTimeCrate::Time => "TimeTime".to_owned(),
68+
DateTimeCrate::Jiff => "JiffTime".to_owned(),
6769
},
6870
ColumnType::DateTime => match opt.date_time_crate {
6971
DateTimeCrate::Chrono => "DateTime".to_owned(),
7072
DateTimeCrate::Time => "TimeDateTime".to_owned(),
73+
DateTimeCrate::Jiff => "JiffDateTime".to_owned(),
7174
},
7275
ColumnType::Timestamp => match opt.date_time_crate {
7376
DateTimeCrate::Chrono => "DateTimeUtc".to_owned(),
7477
DateTimeCrate::Time => "TimeDateTime".to_owned(),
78+
DateTimeCrate::Jiff => "JiffDateTime".to_owned(),
7579
},
7680
ColumnType::TimestampWithTimeZone => match opt.date_time_crate {
7781
DateTimeCrate::Chrono => "DateTimeWithTimeZone".to_owned(),
7882
DateTimeCrate::Time => "TimeDateTimeWithTimeZone".to_owned(),
83+
DateTimeCrate::Jiff => "JiffTimestamp".to_owned(),
7984
},
8085
ColumnType::Decimal(_) | ColumnType::Money(_) => "Decimal".to_owned(),
8186
ColumnType::Uuid => "Uuid".to_owned(),
@@ -107,6 +112,7 @@ impl Column {
107112

108113
pub fn get_col_type_attrs(&self) -> Option<TokenStream> {
109114
let col_type = match &self.col_type {
115+
ColumnType::DateTime => Some("DateTime".to_owned()),
110116
ColumnType::Float => Some("Float".to_owned()),
111117
ColumnType::Double => Some("Double".to_owned()),
112118
ColumnType::Decimal(Some((p, s))) => Some(format!("Decimal(Some(({p}, {s})))")),
@@ -329,6 +335,13 @@ mod tests {
329335
}
330336
}
331337

338+
fn date_time_crate_jiff() -> ColumnOption {
339+
ColumnOption {
340+
date_time_crate: DateTimeCrate::Jiff,
341+
big_integer_type: Default::default(),
342+
}
343+
}
344+
332345
fn setup() -> Vec<Column> {
333346
macro_rules! make_col {
334347
($name:expr, $col_type:expr) => {
@@ -526,6 +539,48 @@ mod tests {
526539
quote!(Option<#rs_type>).to_string()
527540
);
528541
}
542+
543+
let columns = setup();
544+
let rs_types = vec![
545+
"String",
546+
"String",
547+
"String",
548+
"i8",
549+
"u8",
550+
"i16",
551+
"u16",
552+
"i32",
553+
"u32",
554+
"i64",
555+
"u64",
556+
"f32",
557+
"f64",
558+
"Vec<u8>",
559+
"Vec<u8>",
560+
"Vec<u8>",
561+
"Vec<u8>",
562+
"bool",
563+
"JiffDate",
564+
"JiffTime",
565+
"JiffDateTime",
566+
"JiffDateTime",
567+
"JiffTimestamp",
568+
];
569+
for (mut col, rs_type) in columns.into_iter().zip(rs_types) {
570+
let rs_type: TokenStream = rs_type.parse().unwrap();
571+
572+
col.not_null = true;
573+
assert_eq!(
574+
col.get_rs_type(&date_time_crate_jiff()).to_string(),
575+
quote!(#rs_type).to_string()
576+
);
577+
578+
col.not_null = false;
579+
assert_eq!(
580+
col.get_rs_type(&date_time_crate_jiff()).to_string(),
581+
quote!(Option<#rs_type>).to_string()
582+
);
583+
}
529584
}
530585

531586
#[test]
@@ -712,6 +767,55 @@ mod tests {
712767
column.get_info(&date_time_crate_time()).as_str(),
713768
"Column `timestamp_with_timezone_field`: TimeDateTimeWithTimeZone, not_null"
714769
);
770+
let column: Column = ColumnDef::new(Alias::new("date_field"))
771+
.date()
772+
.not_null()
773+
.to_owned()
774+
.into();
775+
assert_eq!(
776+
column.get_info(&date_time_crate_jiff()).as_str(),
777+
"Column `date_field`: JiffDate, not_null"
778+
);
779+
780+
let column: Column = ColumnDef::new(Alias::new("time_field"))
781+
.time()
782+
.not_null()
783+
.to_owned()
784+
.into();
785+
assert_eq!(
786+
column.get_info(&date_time_crate_jiff()).as_str(),
787+
"Column `time_field`: JiffTime, not_null"
788+
);
789+
790+
let column: Column = ColumnDef::new(Alias::new("date_time_field"))
791+
.date_time()
792+
.not_null()
793+
.to_owned()
794+
.into();
795+
assert_eq!(
796+
column.get_info(&date_time_crate_jiff()).as_str(),
797+
"Column `date_time_field`: JiffDateTime, not_null"
798+
);
799+
800+
let column: Column = ColumnDef::new(Alias::new("timestamp_field"))
801+
.timestamp()
802+
.not_null()
803+
.to_owned()
804+
.into();
805+
assert_eq!(
806+
column.get_info(&date_time_crate_jiff()).as_str(),
807+
"Column `timestamp_field`: JiffDateTime, not_null"
808+
);
809+
810+
let column: Column = ColumnDef::new(Alias::new("timestamp_with_timezone_field"))
811+
.timestamp_with_time_zone()
812+
.not_null()
813+
.to_owned()
814+
.into();
815+
assert_eq!(
816+
column.get_info(&date_time_crate_jiff()).as_str(),
817+
"Column `timestamp_with_timezone_field`: JiffTimestamp, not_null"
818+
);
715819
}
716820

717821
#[test]

sea-orm-codegen/src/entity/writer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub enum DateTimeCrate {
4949
#[default]
5050
Chrono,
5151
Time,
52+
Jiff,
5253
}
5354

5455
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]

sea-orm-migration/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ sqlx-sqlite = ["sqlx-dep", "sea-orm/sqlx-sqlite", "sea-orm-cli?/sqlx-sqlite"]
8888
with-bigdecimal = ["sea-orm/with-bigdecimal"]
8989
with-chrono = ["sea-orm/with-chrono"]
9090
with-ipnetwork = ["sea-orm/with-ipnetwork"]
91+
with-jiff = ["sea-orm/with-jiff"]
9192
with-json = ["sea-orm/with-json"]
9293
with-rust_decimal = ["sea-orm/with-rust_decimal"]
9394
with-time = ["sea-orm/with-time"]

sea-orm-sync/Cargo.toml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ features = [
2424
"schema-sync",
2525
"postgres-array",
2626
"postgres-vector",
27+
"tracing-spans",
28+
"with-ipnetwork",
2729
"with-arrow",
2830
]
2931
rustdoc-args = ["--cfg", "docsrs"]
@@ -41,17 +43,22 @@ derive_more = { version = "2", features = ["debug"] }
4143
inventory = { version = "0.3", optional = true }
4244
ipnetwork = { version = "0.20", default-features = false, optional = true }
4345
itertools = "0.14.0"
46+
jiff = { version = "0.2.15", default-features = false, optional = true, features = [
47+
"std",
48+
"perf-inline",
49+
] }
50+
jiff-sqlx = { version = "0.1.1", default-features = false, optional = true }
4451
log = { version = "0.4", default-features = false }
4552
ouroboros = { version = "0.18", default-features = false }
4653
pgvector = { version = "~0.4", default-features = false, optional = true }
4754
rust_decimal = { version = "1", default-features = false, features = [
4855
"std",
4956
], optional = true }
5057
sea-orm-arrow = { version = "2.0.0-rc", path = "../sea-orm-arrow", default-features = false, optional = true }
51-
sea-orm-macros = { version = "~2.0.0-rc.20", path = "../sea-orm-macros", default-features = false, features = [
58+
sea-orm-macros = { version = "~2.0.0-rc.37", path = "../sea-orm-macros", default-features = false, features = [
5259
"strum",
5360
] }
54-
sea-query = { version = "=1.0.0-rc.31", default-features = false, features = [
61+
sea-query = { version = "=1.0.0-rc.32", default-features = false, features = [
5562
"thread-safe",
5663
"hashable-value",
5764
"backend-mysql",
@@ -68,7 +75,7 @@ sea-schema-sync = { version = "0.17.0-rc.15", default-features = false, features
6875
], optional = true }
6976
serde = { version = "1.0", default-features = false }
7077
serde_json = { version = "1.0", default-features = false, optional = true }
71-
strum = { version = "0.27", default-features = false }
78+
strum = { version = "0.28", default-features = false }
7279
thiserror = { version = "2", default-features = false }
7380
time = { version = "0.3.36", default-features = false, optional = true }
7481
tracing = { version = "0.1", default-features = false, features = [
@@ -137,10 +144,13 @@ sync = []
137144
tests-cfg = ["serde/derive"]
138145
tests-features = [
139146
"default",
147+
"postgres-array",
140148
"rbac",
141149
"schema-sync",
142150
"with-arrow",
143151
"with-bigdecimal",
152+
"with-jiff",
153+
"with-ipnetwork",
144154
]
145155
tracing-spans = []
146156
with-arrow = ["sea-orm-arrow", "sea-orm-macros/with-arrow"]
@@ -161,11 +171,18 @@ with-ipnetwork = [
161171
"sea-query/with-ipnetwork",
162172
"sea-query-rusqlite?/with-ipnetwork",
163173
]
174+
with-jiff = [
175+
"jiff",
176+
"jiff-sqlx",
177+
"sea-query/with-jiff",
178+
"sea-query-rusqlite?/with-jiff",
179+
]
164180
with-json = [
165181
"serde_json",
166182
"sea-query/with-json",
167183
"sea-orm-macros/with-json",
168184
"chrono?/serde",
185+
"jiff?/serde",
169186
"rust_decimal?/serde",
170187
"bigdecimal?/serde",
171188
"uuid?/serde",
@@ -188,5 +205,5 @@ with-time = [
188205
with-uuid = ["uuid", "sea-query/with-uuid", "sea-query-rusqlite?/with-uuid"]
189206

190207
[patch.crates-io]
191-
sea-query = { git = "https://github.com/Huliiiiii/sea-query", branch = "jiff" }
208+
sea-query = { git = "https://github.com/Huliiiiii/sea-query", branch = "jiff" }
192209
sea-query-rusqlite = { git = "https://github.com/Huliiiiii/sea-query", branch = "jiff" }

0 commit comments

Comments
 (0)