Skip to content

Commit d379c80

Browse files
committed
jiff sqlx binder
1 parent c68b46b commit d379c80

File tree

4 files changed

+120
-8
lines changed

4 files changed

+120
-8
lines changed

sea-query-binder/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,24 @@ rust_decimal = { version = "1", default-features = false, optional = true }
2525
bigdecimal = { version = "0.4", default-features = false, optional = true }
2626
uuid = { version = "1", default-features = false, optional = true }
2727
time = { version = "0.3.36", default-features = false, optional = true, features = ["macros", "formatting"] }
28+
jiff = { version = "0.2.15", default-features = false, optional = true, features = ["std", "perf-inline"] }
29+
jiff-sqlx = { version = "0.1", optional = true }
2830
ipnetwork = { version = "0.20", default-features = false, optional = true }
2931
mac_address = { version = "1.1", default-features = false, optional = true }
3032
pgvector = { version = "~0.4", default-features = false, optional = true }
3133

3234
[features]
3335
sqlx-mysql = ["sqlx/mysql"]
34-
sqlx-postgres = ["sqlx/postgres"]
35-
sqlx-sqlite = ["sqlx/sqlite"]
36+
sqlx-postgres = ["sqlx/postgres", "jiff-sqlx?/postgres"]
37+
sqlx-sqlite = ["sqlx/sqlite", "jiff-sqlx?/sqlite"]
3638
sqlx-any = ["sqlx/any"]
3739
with-chrono = ["sqlx?/chrono", "sea-query/with-chrono", "chrono"]
3840
with-json = ["sqlx?/json", "sea-query/with-json", "serde_json"]
3941
with-rust_decimal = ["sqlx?/rust_decimal", "sea-query/with-rust_decimal", "rust_decimal"]
4042
with-bigdecimal = ["sqlx?/bigdecimal", "sea-query/with-bigdecimal", "bigdecimal"]
4143
with-uuid = ["sqlx?/uuid", "sea-query/with-uuid", "uuid"]
4244
with-time = ["sqlx?/time", "sea-query/with-time", "time"]
45+
with-jiff = ["sea-query/with-jiff", "jiff", "jiff-sqlx"]
4346
with-ipnetwork = ["sqlx?/ipnetwork", "sea-query/with-ipnetwork", "ipnetwork"]
4447
with-mac_address = ["sqlx?/mac_address", "sea-query/with-mac_address", "mac_address"]
4548
postgres-array = ["sea-query/postgres-array"]

sea-query-binder/src/sqlx_postgres.rs

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use serde_json::Value as Json;
1313
#[cfg(feature = "with-uuid")]
1414
use uuid::Uuid;
1515

16-
use sea_query::{ArrayType, Value};
16+
use sea_query::{ArrayType, Value, ValueType};
1717

1818
use crate::SqlxValues;
1919

@@ -105,6 +105,26 @@ impl sqlx::IntoArguments<'_, sqlx::postgres::Postgres> for SqlxValues {
105105
Value::TimeDateTimeWithTimeZone(t) => {
106106
let _ = args.add(t);
107107
}
108+
#[cfg(feature = "with-jiff")]
109+
Value::JiffDate(j) => {
110+
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
111+
}
112+
#[cfg(feature = "with-jiff")]
113+
Value::JiffTime(j) => {
114+
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
115+
}
116+
#[cfg(feature = "with-jiff")]
117+
Value::JiffDateTime(j) => {
118+
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
119+
}
120+
#[cfg(feature = "with-jiff")]
121+
Value::JiffTimestamp(j) => {
122+
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
123+
}
124+
#[cfg(feature = "with-jiff")]
125+
Value::JiffZoned(_) => {
126+
unimplemented!("no support by jiff-sqlx");
127+
}
108128
#[cfg(feature = "with-uuid")]
109129
Value::Uuid(uuid) => {
110130
let _ = args.add(uuid);
@@ -277,6 +297,75 @@ impl sqlx::IntoArguments<'_, sqlx::postgres::Postgres> for SqlxValues {
277297
);
278298
let _ = args.add(value);
279299
}
300+
#[cfg(feature = "with-jiff")]
301+
ArrayType::JiffDate => {
302+
let value = match v {
303+
Some(j) => Some(
304+
j.into_iter()
305+
.map(|j| {
306+
jiff_sqlx::ToSqlx::to_sqlx(
307+
<jiff::civil::Date as ValueType>::try_from(j).unwrap(),
308+
)
309+
})
310+
.collect::<Vec<_>>(),
311+
),
312+
None => None,
313+
};
314+
let _ = args.add(value);
315+
}
316+
#[cfg(feature = "with-jiff")]
317+
ArrayType::JiffTime => {
318+
let value = match v {
319+
Some(j) => Some(
320+
j.into_iter()
321+
.map(|j| {
322+
jiff_sqlx::ToSqlx::to_sqlx(
323+
<jiff::civil::Time as ValueType>::try_from(j).unwrap(),
324+
)
325+
})
326+
.collect::<Vec<_>>(),
327+
),
328+
None => None,
329+
};
330+
let _ = args.add(value);
331+
}
332+
#[cfg(feature = "with-jiff")]
333+
ArrayType::JiffDateTime => {
334+
let value = match v {
335+
Some(j) => Some(
336+
j.into_iter()
337+
.map(|j| {
338+
jiff_sqlx::ToSqlx::to_sqlx(
339+
<jiff::civil::DateTime as ValueType>::try_from(j)
340+
.unwrap(),
341+
)
342+
})
343+
.collect::<Vec<_>>(),
344+
),
345+
None => None,
346+
};
347+
let _ = args.add(value);
348+
}
349+
#[cfg(feature = "with-jiff")]
350+
ArrayType::JiffTimestamp => {
351+
let value = match v {
352+
Some(j) => Some(
353+
j.into_iter()
354+
.map(|j| {
355+
jiff_sqlx::ToSqlx::to_sqlx(
356+
<jiff::Timestamp as ValueType>::try_from(j).unwrap(),
357+
)
358+
})
359+
.collect::<Vec<_>>(),
360+
),
361+
None => None,
362+
};
363+
let _ = args.add(value);
364+
}
365+
#[cfg(feature = "with-jiff")]
366+
ArrayType::JiffZoned => {
367+
unimplemented!("no support by jiff-sqlx");
368+
}
280369
#[cfg(feature = "with-uuid")]
281370
ArrayType::Uuid => {
282371
let value: Option<Vec<Uuid>> = Value::Array(ty, v)

sea-query-binder/src/sqlx_sqlite.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::sqlite::Sqlite> for SqlxValues {
9090
Value::TimeDateTimeWithTimeZone(t) => {
9191
let _ = args.add(t);
9292
}
93+
#[cfg(feature = "with-jiff")]
94+
Value::JiffDate(j) => {
95+
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
96+
}
97+
#[cfg(feature = "with-jiff")]
98+
Value::JiffTime(j) => {
99+
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
100+
}
101+
#[cfg(feature = "with-jiff")]
102+
Value::JiffDateTime(j) => {
103+
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
104+
}
105+
#[cfg(feature = "with-jiff")]
106+
Value::JiffTimestamp(j) => {
107+
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
108+
}
109+
#[cfg(feature = "with-jiff")]
110+
Value::JiffZoned(_) => {
111+
unimplemented!("no support by jiff-sqlx");
112+
}
93113
#[cfg(feature = "with-uuid")]
94114
Value::Uuid(uuid) => {
95115
let _ = args.add(uuid);

src/value.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use chrono::{DateTime, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime,
1414
use time::{OffsetDateTime, PrimitiveDateTime};
1515

1616
#[cfg(feature = "with-jiff")]
17-
use jiff::{Timestamp, Zoned};
17+
use jiff::{Timestamp as JiffTimestamp, Zoned as JiffZoned};
1818

1919
#[cfg(feature = "with-rust_decimal")]
2020
use rust_decimal::Decimal;
@@ -284,11 +284,11 @@ pub enum Value {
284284

285285
#[cfg(feature = "with-jiff")]
286286
#[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))]
287-
JiffTimestamp(Option<Timestamp>),
287+
JiffTimestamp(Option<JiffTimestamp>),
288288

289289
#[cfg(feature = "with-jiff")]
290290
#[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))]
291-
JiffZoned(Option<Zoned>),
291+
JiffZoned(Option<JiffZoned>),
292292

293293
#[cfg(feature = "with-uuid")]
294294
#[cfg_attr(docsrs, doc(cfg(feature = "with-uuid")))]
@@ -561,12 +561,12 @@ impl Value {
561561

562562
#[cfg(feature = "with-jiff")]
563563
#[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))]
564-
Self::JiffTimestamp(_) => Self::JiffTimestamp(Some(Timestamp::UNIX_EPOCH)),
564+
Self::JiffTimestamp(_) => Self::JiffTimestamp(Some(JiffTimestamp::UNIX_EPOCH)),
565565

566566
#[cfg(feature = "with-jiff")]
567567
#[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))]
568568
Self::JiffZoned(_) => Self::JiffZoned(Some(
569-
Timestamp::UNIX_EPOCH.to_zoned(jiff::tz::TimeZone::UTC),
569+
JiffTimestamp::UNIX_EPOCH.to_zoned(jiff::tz::TimeZone::UTC),
570570
)),
571571

572572
#[cfg(feature = "with-uuid")]

0 commit comments

Comments
 (0)