Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ pub struct ColumnName(pub Option<TableName>, pub DynIden);

### Enhancements

* Supports Jiff types except `jiff::Zoned`.
At the moment this support is only available through the SQLx binder.
When using SQLx with multiple backends, enable `unimplemented-jiff-sqlx-mysql` to suppress the
compile-time error. After enabling it, runtime panics may occur.
* Add `Expr::not_exists` https://github.com/SeaQL/sea-query/pull/983
* Add `serde` feature. Currently, enabling it allows `Value` to be serializable https://github.com/SeaQL/sea-query/pull/966
* Add `Keyword::Default` https://github.com/SeaQL/sea-query/pull/965
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ with-bigdecimal = ["bigdecimal"]
with-uuid = ["uuid"]
with-time = ["time"]
with-jiff = ["jiff"]
unimplemented-jiff-zoned = []
with-ipnetwork = ["ipnetwork"]
with-mac_address = ["mac_address"]
sqlx-utils = ["derive"]
Expand Down
2 changes: 2 additions & 0 deletions examples/sqlx_postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ publish = false

[dependencies]
time = { version = "0.3.36", features = ["macros"] }
jiff = { version = "0.2.15", features = ["std"] }
uuid = { version = "1", features = ["serde", "v4"] }
serde_json = { version = "1" }
async-std = { version = "1.8", features = [ "attributes" ] }
Expand All @@ -23,6 +24,7 @@ sea-query-sqlx = { path = "../../sea-query-sqlx", 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 @@ -20,9 +20,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 @@ -72,11 +79,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
9 changes: 7 additions & 2 deletions sea-query-sqlx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ sea-query = { version = "1.0.0-rc.30", path = "..", default-features = false, fe
sqlx = { version = "0.8", default-features = false, optional = true }
ipnetwork = { version = "0.20", default-features = false, optional = true } # pin dependency
pgvector = { version = "0.4", default-features = false, optional = true } # requires feature flag
jiff = { version = "0.2.15", default-features = false, optional = true, features = ["std", "perf-inline"] }
jiff-sqlx = { version = "0.1", optional = true }

[features]
sqlx-mysql = ["sqlx/mysql"]
sqlx-postgres = ["sqlx/postgres", "sea-query/backend-postgres"]
sqlx-sqlite = ["sqlx/sqlite"]
sqlx-postgres = ["sqlx/postgres", "sea-query/backend-postgres", "jiff-sqlx?/postgres"]
sqlx-sqlite = ["sqlx/sqlite", "jiff-sqlx?/sqlite"]
sqlx-any = ["sqlx/any"]
with-chrono = ["sqlx?/chrono", "sea-query/with-chrono"]
with-json = ["sqlx?/json", "sea-query/with-json"]
Expand All @@ -35,6 +37,9 @@ with-uuid = ["sqlx?/uuid", "sea-query/with-uuid"]
with-time = ["sqlx?/time", "sea-query/with-time"]
with-ipnetwork = ["sqlx?/ipnetwork", "sea-query/with-ipnetwork"]
with-mac_address = ["sqlx?/mac_address", "sea-query/with-mac_address"]
with-jiff = ["sea-query/with-jiff", "jiff", "jiff-sqlx"]
unimplemented-jiff-sqlx-mysql = []
unimplemented-jiff-zoned = ["sea-query/unimplemented-jiff-zoned"]
postgres-array = ["sea-query/postgres-array"]
postgres-vector = ["sea-query/postgres-vector", "pgvector/sqlx"]
runtime-async-std = ["sqlx?/runtime-async-std"]
Expand Down
11 changes: 11 additions & 0 deletions sea-query-sqlx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
//!
//! [1]: ../sqlx/fn.query_with.html

#[cfg(all(
any(feature = "sqlx-mysql", feature = "sqlx-any"),
feature = "with-jiff",
not(feature = "unimplemented-jiff-sqlx-mysql")
))]
const _: () = panic!(
"sea-query-sqlx does not support with-jiff together with sqlx-mysql/sqlx-any yet; \
enable the `unimplemented-jiff-sqlx-mysql` feature to acknowledge the limitation and keep the \
current runtime panic behavior"
);

#[cfg(feature = "sqlx-any")]
mod sqlx_any;
#[cfg(feature = "sqlx-mysql")]
Expand Down
31 changes: 28 additions & 3 deletions sea-query-sqlx/src/sqlx_any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::any::Any> for SqlxValues {
let _ =
args.add(Value::TimeDateTimeWithTimeZone(t).time_as_naive_utc_in_string());
}
#[cfg(feature = "with-jiff")]
Value::JiffDate(_) => {
panic!("Jiff support not implemented for Any");
}
#[cfg(feature = "with-jiff")]
Value::JiffTime(_) => {
panic!("Jiff support not implemented for Any");
}
#[cfg(feature = "with-jiff")]
Value::JiffDateTime(_) => {
panic!("Jiff support not implemented for Any");
}
#[cfg(feature = "with-jiff")]
Value::JiffTimestamp(_) => {
panic!("Jiff support not implemented for Any");
}
#[cfg(all(feature = "with-jiff", feature = "unimplemented-jiff-zoned"))]
Value::JiffZoned(_) => {
panic!("Jiff support not implemented for Any");
}
#[cfg(feature = "with-uuid")]
Value::Uuid(_) => {
panic!("UUID support not implemented for Any");
Expand Down Expand Up @@ -131,9 +151,14 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::any::Any> for SqlxValues {
Value::Vector(_) => {
panic!("SQLx doesn't support vector arguments for Any");
} /* #[cfg(feature = "postgres-range")]
Value::Range(_) => {
panic!("SQLx doesn't support PgRange arguments for Any");
} */
Value::Range(_) => {
panic!("SQLx doesn't support PgRange arguments for Any");
} */
#[cfg(all(feature = "with-jiff", not(feature = "unimplemented-jiff-zoned")))]
other => {
let _ = other;
panic!("JiffZoned support not implemented for Any");
}
}
}
args
Expand Down
31 changes: 28 additions & 3 deletions sea-query-sqlx/src/sqlx_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@ impl sqlx::IntoArguments<'_, sqlx::mysql::MySql> for SqlxValues {
Value::TimeDateTimeWithTimeZone(t) => {
let _ = args.add(t);
}
#[cfg(feature = "with-jiff")]
Value::JiffDate(_) => {
panic!("Mysql doesn't support JiffDate arguments");
}
#[cfg(feature = "with-jiff")]
Value::JiffTime(_) => {
panic!("Mysql doesn't support JiffTime arguments");
}
#[cfg(feature = "with-jiff")]
Value::JiffDateTime(_) => {
panic!("Mysql doesn't support JiffDateTime arguments");
}
#[cfg(feature = "with-jiff")]
Value::JiffTimestamp(_) => {
panic!("Mysql doesn't support JiffTimestamp arguments");
}
#[cfg(all(feature = "with-jiff", feature = "unimplemented-jiff-zoned"))]
Value::JiffZoned(_) => {
panic!("Mysql doesn't support JiffZoned arguments");
}
#[cfg(feature = "with-uuid")]
Value::Uuid(uuid) => {
let _ = args.add(uuid);
Expand Down Expand Up @@ -129,9 +149,14 @@ impl sqlx::IntoArguments<'_, sqlx::mysql::MySql> for SqlxValues {
Value::MacAddress(_) => {
panic!("Mysql doesn't support MacAddress arguments");
} /* #[cfg(feature = "postgres-range")]
Value::Range(_) => {
panic!("Mysql doesn't support PgRange arguments");
} */
Value::Range(_) => {
panic!("Mysql doesn't support PgRange arguments");
} */
#[cfg(all(feature = "with-jiff", not(feature = "unimplemented-jiff-zoned")))]
other => {
let _ = other;
panic!("Mysql doesn't support JiffZoned arguments");
}
}
}
args
Expand Down
110 changes: 106 additions & 4 deletions sea-query-sqlx/src/sqlx_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use sea_query::prelude::time;
#[cfg(feature = "with-chrono")]
use sea_query::prelude::{DateTime, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, Utc};

use sea_query::{ArrayType, OptionEnum, Value};
#[cfg(feature = "postgres-array")]
use sea_query::{ArrayType, ValueType};
use sea_query::{OptionEnum, Value};

use crate::SqlxValues;

Expand Down Expand Up @@ -114,6 +116,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(all(feature = "with-jiff", feature = "unimplemented-jiff-zoned"))]
Value::JiffZoned(_) => {
unimplemented!("no support by jiff-sqlx");
}
#[cfg(feature = "with-uuid")]
Value::Uuid(uuid) => {
let _ = args.add(uuid);
Expand Down Expand Up @@ -302,6 +324,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(all(feature = "with-jiff", feature = "unimplemented-jiff-zoned"))]
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 Expand Up @@ -338,14 +429,25 @@ impl sqlx::IntoArguments<'_, sqlx::postgres::Postgres> for SqlxValues {
.expect("This Value::Array should consist of Value::MacAddress");
let _ = args.add(value);
}
#[cfg(all(
feature = "with-jiff",
not(feature = "unimplemented-jiff-zoned")
))]
ArrayType::JiffZoned => {
panic!("Postgres doesn't support JiffZoned array arguments");
}
},
#[cfg(feature = "postgres-vector")]
Value::Vector(v) => {
let _ = args.add(v);
} /* #[cfg(feature = "postgres-range")]
Value::Range(v) => {
let _ = args.add(v);
} */
Value::Range(v) => {
let _ = args.add(v);
} */
#[cfg(all(feature = "with-jiff", not(feature = "unimplemented-jiff-zoned")))]
Value::JiffZoned(_) => {
panic!("Postgres doesn't support JiffZoned arguments");
}
}
}
args
Expand Down
30 changes: 27 additions & 3 deletions sea-query-sqlx/src/sqlx_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,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| j.to_string()));
}
#[cfg(feature = "with-jiff")]
Value::JiffTime(j) => {
let _ = args.add(j.map(|j| j.to_string()));
}
#[cfg(feature = "with-jiff")]
Value::JiffDateTime(j) => {
let _ = args.add(j.map(|j| j.to_string()));
}
#[cfg(feature = "with-jiff")]
Value::JiffTimestamp(j) => {
let _ = args.add(j.map(|j| j.to_string()));
}
#[cfg(all(feature = "with-jiff", feature = "unimplemented-jiff-zoned"))]
Value::JiffZoned(_) => {
unimplemented!("no support by jiff-sqlx");
}
#[cfg(feature = "with-uuid")]
Value::Uuid(uuid) => {
let _ = args.add(uuid);
Expand Down Expand Up @@ -130,9 +150,13 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::sqlite::Sqlite> for SqlxValues {
Value::Vector(_) => {
panic!("Sqlite doesn't support vector arguments");
} /* #[cfg(feature = "postgres-range")]
Value::Range(_) => {
panic!("Sqlite doesn't support PgRange arguments");
} */
Value::Range(_) => {
panic!("Sqlite doesn't support PgRange arguments");
} */
#[cfg(all(feature = "with-jiff", not(feature = "unimplemented-jiff-zoned")))]
Value::JiffZoned(_) => {
panic!("Sqlite doesn't support JiffZoned arguments");
}
}
}
args
Expand Down
Loading
Loading