Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
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
3 changes: 2 additions & 1 deletion sea-query-rusqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ with-rust_decimal = ["sea-query/with-rust_decimal"]
with-bigdecimal = ["sea-query/with-bigdecimal"]
with-uuid = ["rusqlite/uuid", "sea-query/with-uuid"]
with-time = ["rusqlite/time", "sea-query/with-time"]
with-jiff = ["rusqlite/jiff", "sea-query/with-jiff"]
with-ipnetwork = ["sea-query/with-ipnetwork"]
with-mac_address = ["sea-query/with-mac_address"]
postgres-array = ["sea-query/postgres-array"]
postgres-vector = ["sea-query/postgres-vector"]
sea-orm = []
sea-orm = []
8 changes: 8 additions & 0 deletions sea-query-rusqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ impl ToSql for RusqliteValue {
Value::TimeDateTime(v) => v.to_sql(),
#[cfg(feature = "with-time")]
Value::TimeDateTimeWithTimeZone(v) => v.to_sql(),
#[cfg(feature = "with-jiff")]
Value::JiffDate(v) => v.to_sql(),
#[cfg(feature = "with-jiff")]
Value::JiffTime(v) => v.to_sql(),
#[cfg(feature = "with-jiff")]
Value::JiffDateTime(v) => v.to_sql(),
#[cfg(feature = "with-jiff")]
Value::JiffTimestamp(v) => v.to_sql(),
#[cfg(feature = "with-uuid")]
Value::Uuid(v) => v.to_sql(),
#[cfg(feature = "with-json")]
Expand Down
8 changes: 6 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,8 @@ 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 = []
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
18 changes: 17 additions & 1 deletion sea-query-sqlx/src/sqlx_any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ 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(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(feature = "with-uuid")]
Value::Uuid(_) => {
panic!("UUID support not implemented for Any");
Expand Down Expand Up @@ -132,7 +148,7 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::any::Any> for SqlxValues {
panic!("SQLx doesn't support vector arguments for Any");
} /* #[cfg(feature = "postgres-range")]
Value::Range(_) => {
panic!("SQLx doesn't support PgRange arguments for Any");
panic!("SQLx doesn't support PgRange arguments for Any");
} */
}
}
Expand Down
18 changes: 17 additions & 1 deletion sea-query-sqlx/src/sqlx_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ 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(feature = "with-uuid")]
Value::Uuid(uuid) => {
let _ = args.add(uuid);
Expand Down Expand Up @@ -130,7 +146,7 @@ impl sqlx::IntoArguments<'_, sqlx::mysql::MySql> for SqlxValues {
panic!("Mysql doesn't support MacAddress arguments");
} /* #[cfg(feature = "postgres-range")]
Value::Range(_) => {
panic!("Mysql doesn't support PgRange arguments");
panic!("Mysql doesn't support PgRange arguments");
} */
}
}
Expand Down
87 changes: 85 additions & 2 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,22 @@ 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-uuid")]
Value::Uuid(uuid) => {
let _ = args.add(uuid);
Expand Down Expand Up @@ -302,6 +320,71 @@ 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-uuid")]
ArrayType::Uuid => {
let value: Option<Vec<Uuid>> = Value::Array(ty, v)
Expand Down Expand Up @@ -344,7 +427,7 @@ impl sqlx::IntoArguments<'_, sqlx::postgres::Postgres> for SqlxValues {
let _ = args.add(v);
} /* #[cfg(feature = "postgres-range")]
Value::Range(v) => {
let _ = args.add(v);
let _ = args.add(v);
} */
}
}
Expand Down
19 changes: 17 additions & 2 deletions sea-query-sqlx/src/sqlx_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ 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(feature = "with-uuid")]
Value::Uuid(uuid) => {
let _ = args.add(uuid);
Expand All @@ -107,7 +123,6 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::sqlite::Sqlite> for SqlxValues {
}
#[cfg(feature = "with-bigdecimal")]
Value::BigDecimal(big_decimal) => {
use sea_query::prelude::bigdecimal::ToPrimitive;
let _ = args.add(big_decimal.map(|d| d.to_string()));
}
#[cfg(feature = "with-json")]
Expand All @@ -131,7 +146,7 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::sqlite::Sqlite> for SqlxValues {
panic!("Sqlite doesn't support vector arguments");
} /* #[cfg(feature = "postgres-range")]
Value::Range(_) => {
panic!("Sqlite doesn't support PgRange arguments");
panic!("Sqlite doesn't support PgRange arguments");
} */
}
}
Expand Down
19 changes: 2 additions & 17 deletions src/backend/query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,6 @@ pub trait QueryBuilder:
Value::JiffDateTime(None) => buf.write_str("NULL")?,
#[cfg(feature = "with-jiff")]
Value::JiffTimestamp(None) => buf.write_str("NULL")?,
#[cfg(feature = "with-jiff")]
Value::JiffZoned(None) => buf.write_str("NULL")?,
#[cfg(feature = "with-rust_decimal")]
Value::Decimal(None) => buf.write_str("NULL")?,
#[cfg(feature = "with-bigdecimal")]
Expand Down Expand Up @@ -1338,8 +1336,6 @@ pub trait QueryBuilder:
buf.write_str(&v.format(time_format::FORMAT_DATETIME_TZ).unwrap())?;
buf.write_str("'")?;
}
// Jiff date and time dosen't need format string
// The default behavior is what we want
#[cfg(feature = "with-jiff")]
Value::JiffDate(Some(v)) => {
buf.write_str("'")?;
Expand All @@ -1352,27 +1348,16 @@ pub trait QueryBuilder:
write!(buf, "{v}")?;
buf.write_str("'")?;
}
// Both JiffDateTime and JiffTimestamp map to timestamp
#[cfg(feature = "with-jiff")]
Value::JiffDateTime(Some(v)) => {
use crate::with_jiff::JIFF_DATE_TIME_FMT_STR;
buf.write_str("'")?;
write!(buf, "{}", v.strftime(JIFF_DATE_TIME_FMT_STR))?;
write!(buf, "{v}")?;
buf.write_str("'")?;
}
#[cfg(feature = "with-jiff")]
Value::JiffTimestamp(Some(v)) => {
use crate::with_jiff::JIFF_TIMESTAMP_FMT_STR;
buf.write_str("'")?;
write!(buf, "{}", v.strftime(JIFF_TIMESTAMP_FMT_STR))?;
buf.write_str("'")?;
}
#[cfg(feature = "with-jiff")]
// Zoned map to timestamp with timezone
Value::JiffZoned(Some(v)) => {
use crate::with_jiff::JIFF_ZONE_FMT_STR;
buf.write_str("'")?;
write!(buf, "{}", v.strftime(JIFF_ZONE_FMT_STR))?;
write!(buf, "{v}")?;
buf.write_str("'")?;
}
#[cfg(feature = "with-rust_decimal")]
Expand Down
Loading
Loading