Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/sqlx_postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ publish = false
[dependencies]
chrono = { version = "0.4", default-features = false, features = ["clock"] }
time = { version = "0.3.36", features = ["macros"] }
jiff = { version = "0.2.15", features = ["std"] }
uuid = { version = "1", features = ["serde", "v4"] }
serde_json = "1"
rust_decimal = { version = "1" }
Expand All @@ -28,6 +29,7 @@ sea-query-binder = { path = "../../sea-query-binder", features = [
"with-bigdecimal",
"with-uuid",
"with-time",
"with-jiff",
"with-ipnetwork",
"with-mac_address",
"runtime-async-std-native-tls",
Expand Down
20 changes: 14 additions & 6 deletions examples/sqlx_postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ async fn main() {

// Schema

let sql = Table::drop()
.table(Character::Table)
.if_exists()
.build(PostgresQueryBuilder);

let result = sqlx::query(&sql).execute(&mut *pool).await;
println!("Drop table character: {result:?}\n");

let sql = Table::create()
.table(Character::Table)
.if_not_exists()
.col(
ColumnDef::new(Character::Id)
.integer()
Expand Down Expand Up @@ -78,11 +85,12 @@ async fn main() {
.unwrap()
.with_scale(3)
.into(),
NaiveDate::from_ymd_opt(2020, 8, 20)
.unwrap()
.and_hms_opt(0, 0, 0)
.unwrap()
.into(),
// NaiveDate::from_ymd_opt(2020, 8, 20)
// .unwrap()
// .and_hms_opt(0, 0, 0)
// .unwrap()
// .into(),
jiff::civil::date(2020, 8, 20).at(0, 0, 0, 0).into(),
IpNetwork::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8)
.unwrap()
.into(),
Expand Down
7 changes: 5 additions & 2 deletions sea-query-binder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@ rust_decimal = { version = "1", default-features = false, optional = true }
bigdecimal = { version = "0.4", default-features = false, optional = true }
uuid = { version = "1", default-features = false, optional = true }
time = { version = "0.3.36", default-features = false, optional = true, features = ["macros", "formatting"] }
jiff = { version = "0.2.15", default-features = false, optional = true, features = ["std", "perf-inline"] }
jiff-sqlx = { version = "0.1", optional = true }
ipnetwork = { version = "0.20", default-features = false, optional = true }
mac_address = { version = "1.1", default-features = false, optional = true }
pgvector = { version = "~0.4", default-features = false, optional = true }

[features]
sqlx-mysql = ["sqlx/mysql"]
sqlx-postgres = ["sqlx/postgres"]
sqlx-sqlite = ["sqlx/sqlite"]
sqlx-postgres = ["sqlx/postgres", "jiff-sqlx?/postgres"]
sqlx-sqlite = ["sqlx/sqlite", "jiff-sqlx?/sqlite"]
sqlx-any = ["sqlx/any"]
with-chrono = ["sqlx?/chrono", "sea-query/with-chrono", "chrono"]
with-json = ["sqlx?/json", "sea-query/with-json", "serde_json"]
with-rust_decimal = ["sqlx?/rust_decimal", "sea-query/with-rust_decimal", "rust_decimal"]
with-bigdecimal = ["sqlx?/bigdecimal", "sea-query/with-bigdecimal", "bigdecimal"]
with-uuid = ["sqlx?/uuid", "sea-query/with-uuid", "uuid"]
with-time = ["sqlx?/time", "sea-query/with-time", "time"]
with-jiff = ["sea-query/with-jiff", "jiff", "jiff-sqlx"]
with-ipnetwork = ["sqlx?/ipnetwork", "sea-query/with-ipnetwork", "ipnetwork"]
with-mac_address = ["sqlx?/mac_address", "sea-query/with-mac_address", "mac_address"]
postgres-array = ["sea-query/postgres-array"]
Expand Down
91 changes: 90 additions & 1 deletion sea-query-binder/src/sqlx_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde_json::Value as Json;
#[cfg(feature = "with-uuid")]
use uuid::Uuid;

use sea_query::{ArrayType, Value};
use sea_query::{ArrayType, Value, ValueType};

use crate::SqlxValues;

Expand Down Expand Up @@ -105,6 +105,26 @@ impl sqlx::IntoArguments<'_, sqlx::postgres::Postgres> for SqlxValues {
Value::TimeDateTimeWithTimeZone(t) => {
let _ = args.add(t);
}
#[cfg(feature = "with-jiff")]
Value::JiffDate(j) => {
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
}
#[cfg(feature = "with-jiff")]
Value::JiffTime(j) => {
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
}
#[cfg(feature = "with-jiff")]
Value::JiffDateTime(j) => {
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
}
#[cfg(feature = "with-jiff")]
Value::JiffTimestamp(j) => {
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
}
#[cfg(feature = "with-jiff")]
Value::JiffZoned(_) => {
unimplemented!("no support by jiff-sqlx");
}
#[cfg(feature = "with-uuid")]
Value::Uuid(uuid) => {
let _ = args.add(uuid);
Expand Down Expand Up @@ -277,6 +297,75 @@ impl sqlx::IntoArguments<'_, sqlx::postgres::Postgres> for SqlxValues {
);
let _ = args.add(value);
}
#[cfg(feature = "with-jiff")]
ArrayType::JiffDate => {
let value = match v {
Some(j) => Some(
j.into_iter()
.map(|j| {
jiff_sqlx::ToSqlx::to_sqlx(
<jiff::civil::Date as ValueType>::try_from(j).unwrap(),
)
})
.collect::<Vec<_>>(),
),
None => None,
};
let _ = args.add(value);
}
#[cfg(feature = "with-jiff")]
ArrayType::JiffTime => {
let value = match v {
Some(j) => Some(
j.into_iter()
.map(|j| {
jiff_sqlx::ToSqlx::to_sqlx(
<jiff::civil::Time as ValueType>::try_from(j).unwrap(),
)
})
.collect::<Vec<_>>(),
),
None => None,
};
let _ = args.add(value);
}
#[cfg(feature = "with-jiff")]
ArrayType::JiffDateTime => {
let value = match v {
Some(j) => Some(
j.into_iter()
.map(|j| {
jiff_sqlx::ToSqlx::to_sqlx(
<jiff::civil::DateTime as ValueType>::try_from(j)
.unwrap(),
)
})
.collect::<Vec<_>>(),
),
None => None,
};
let _ = args.add(value);
}
#[cfg(feature = "with-jiff")]
ArrayType::JiffTimestamp => {
let value = match v {
Some(j) => Some(
j.into_iter()
.map(|j| {
jiff_sqlx::ToSqlx::to_sqlx(
<jiff::Timestamp as ValueType>::try_from(j).unwrap(),
)
})
.collect::<Vec<_>>(),
),
None => None,
};
let _ = args.add(value);
}
#[cfg(feature = "with-jiff")]
ArrayType::JiffZoned => {
unimplemented!("no support by jiff-sqlx");
}
#[cfg(feature = "with-uuid")]
ArrayType::Uuid => {
let value: Option<Vec<Uuid>> = Value::Array(ty, v)
Expand Down
20 changes: 20 additions & 0 deletions sea-query-binder/src/sqlx_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,26 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::sqlite::Sqlite> for SqlxValues {
Value::TimeDateTimeWithTimeZone(t) => {
let _ = args.add(t);
}
#[cfg(feature = "with-jiff")]
Value::JiffDate(j) => {
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
}
#[cfg(feature = "with-jiff")]
Value::JiffTime(j) => {
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
}
#[cfg(feature = "with-jiff")]
Value::JiffDateTime(j) => {
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
}
#[cfg(feature = "with-jiff")]
Value::JiffTimestamp(j) => {
let _ = args.add(j.map(|j| jiff_sqlx::ToSqlx::to_sqlx(j)));
}
#[cfg(feature = "with-jiff")]
Value::JiffZoned(_) => {
unimplemented!("no support by jiff-sqlx");
}
#[cfg(feature = "with-uuid")]
Value::Uuid(uuid) => {
let _ = args.add(uuid);
Expand Down
10 changes: 5 additions & 5 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use chrono::{DateTime, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime,
use time::{OffsetDateTime, PrimitiveDateTime};

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

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

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

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

#[cfg(feature = "with-uuid")]
#[cfg_attr(docsrs, doc(cfg(feature = "with-uuid")))]
Expand Down Expand Up @@ -561,12 +561,12 @@ impl Value {

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

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

#[cfg(feature = "with-uuid")]
Expand Down
Loading