diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dedf0790..7ab2d578a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,10 @@ pub struct ColumnName(pub Option, 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 diff --git a/examples/sqlx_postgres/Cargo.toml b/examples/sqlx_postgres/Cargo.toml index bdf2cf50b..fcdf9ae89 100644 --- a/examples/sqlx_postgres/Cargo.toml +++ b/examples/sqlx_postgres/Cargo.toml @@ -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" ] } @@ -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", diff --git a/examples/sqlx_postgres/src/main.rs b/examples/sqlx_postgres/src/main.rs index 4d1f02fdc..5746d8d61 100644 --- a/examples/sqlx_postgres/src/main.rs +++ b/examples/sqlx_postgres/src/main.rs @@ -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() @@ -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(), diff --git a/sea-query-rusqlite/Cargo.toml b/sea-query-rusqlite/Cargo.toml index 462d8911f..9ffbfa784 100644 --- a/sea-query-rusqlite/Cargo.toml +++ b/sea-query-rusqlite/Cargo.toml @@ -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 = [] \ No newline at end of file +sea-orm = [] diff --git a/sea-query-rusqlite/src/lib.rs b/sea-query-rusqlite/src/lib.rs index 69cf4aaf2..2b7ab3194 100644 --- a/sea-query-rusqlite/src/lib.rs +++ b/sea-query-rusqlite/src/lib.rs @@ -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")] diff --git a/sea-query-sqlx/Cargo.toml b/sea-query-sqlx/Cargo.toml index 6d1a1b763..5ba5dccbd 100644 --- a/sea-query-sqlx/Cargo.toml +++ b/sea-query-sqlx/Cargo.toml @@ -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"] @@ -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"] diff --git a/sea-query-sqlx/src/lib.rs b/sea-query-sqlx/src/lib.rs index 482897bbc..adf519c9e 100644 --- a/sea-query-sqlx/src/lib.rs +++ b/sea-query-sqlx/src/lib.rs @@ -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")] diff --git a/sea-query-sqlx/src/sqlx_any.rs b/sea-query-sqlx/src/sqlx_any.rs index 7e064e927..544491791 100644 --- a/sea-query-sqlx/src/sqlx_any.rs +++ b/sea-query-sqlx/src/sqlx_any.rs @@ -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"); @@ -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"); } */ } } diff --git a/sea-query-sqlx/src/sqlx_mysql.rs b/sea-query-sqlx/src/sqlx_mysql.rs index 749171939..ee83ec401 100644 --- a/sea-query-sqlx/src/sqlx_mysql.rs +++ b/sea-query-sqlx/src/sqlx_mysql.rs @@ -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); @@ -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"); } */ } } diff --git a/sea-query-sqlx/src/sqlx_postgres.rs b/sea-query-sqlx/src/sqlx_postgres.rs index defaddc31..e8f68d665 100644 --- a/sea-query-sqlx/src/sqlx_postgres.rs +++ b/sea-query-sqlx/src/sqlx_postgres.rs @@ -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; @@ -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); @@ -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( + ::try_from(j).unwrap(), + ) + }) + .collect::>(), + ), + 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( + ::try_from(j).unwrap(), + ) + }) + .collect::>(), + ), + 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( + ::try_from(j) + .unwrap(), + ) + }) + .collect::>(), + ), + 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( + ::try_from(j).unwrap(), + ) + }) + .collect::>(), + ), + None => None, + }; + let _ = args.add(value); + } #[cfg(feature = "with-uuid")] ArrayType::Uuid => { let value: Option> = Value::Array(ty, v) @@ -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); } */ } } diff --git a/sea-query-sqlx/src/sqlx_sqlite.rs b/sea-query-sqlx/src/sqlx_sqlite.rs index d6ea1b96f..e9c26ab94 100644 --- a/sea-query-sqlx/src/sqlx_sqlite.rs +++ b/sea-query-sqlx/src/sqlx_sqlite.rs @@ -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); @@ -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")] @@ -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"); } */ } } diff --git a/src/backend/query_builder.rs b/src/backend/query_builder.rs index 215004be7..250237755 100644 --- a/src/backend/query_builder.rs +++ b/src/backend/query_builder.rs @@ -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")] @@ -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("'")?; @@ -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")] diff --git a/src/value.rs b/src/value.rs index c385bb943..bd1a31129 100644 --- a/src/value.rs +++ b/src/value.rs @@ -42,7 +42,7 @@ mod with_time; #[cfg(feature = "with-jiff")] #[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))] -pub(crate) mod with_jiff; +pub mod with_jiff; #[cfg(feature = "with-rust_decimal")] #[cfg_attr(docsrs, doc(cfg(feature = "with-rust_decimal")))] @@ -162,10 +162,6 @@ pub enum ArrayType { #[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))] JiffTimestamp, - #[cfg(feature = "with-jiff")] - #[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))] - JiffZoned, - #[cfg(feature = "with-uuid")] #[cfg_attr(docsrs, doc(cfg(feature = "with-uuid")))] Uuid, @@ -298,10 +294,6 @@ pub enum Value { #[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))] JiffTimestamp(Option>), - #[cfg(feature = "with-jiff")] - #[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))] - JiffZoned(Option>), - #[cfg(feature = "with-uuid")] #[cfg_attr(docsrs, doc(cfg(feature = "with-uuid")))] Uuid(Option), @@ -465,10 +457,6 @@ impl Value { #[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))] Self::JiffTimestamp(_) => Self::JiffTimestamp(None), - #[cfg(feature = "with-jiff")] - #[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))] - Self::JiffZoned(_) => Self::JiffZoned(None), - #[cfg(feature = "with-uuid")] #[cfg_attr(docsrs, doc(cfg(feature = "with-uuid")))] Self::Uuid(_) => Self::Uuid(None), @@ -605,14 +593,6 @@ impl Value { #[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))] Self::JiffTimestamp(_) => Self::JiffTimestamp(Some(Timestamp::UNIX_EPOCH.into())), - #[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) - .into(), - )), - #[cfg(feature = "with-uuid")] #[cfg_attr(docsrs, doc(cfg(feature = "with-uuid")))] Self::Uuid(_) => Self::Uuid(Some(Default::default())), @@ -744,10 +724,6 @@ impl Value { #[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))] Self::JiffTimestamp(v) => array_type_of_ref(v.as_ref().map(|v| v.deref())), - #[cfg(feature = "with-jiff")] - #[cfg_attr(docsrs, doc(cfg(feature = "with-jiff")))] - Self::JiffZoned(v) => array_type_of_ref(v.as_ref().map(|v| v.deref())), - #[cfg(feature = "with-uuid")] #[cfg_attr(docsrs, doc(cfg(feature = "with-uuid")))] Self::Uuid(v) => array_type_of(v), diff --git a/src/value/hashable_value.rs b/src/value/hashable_value.rs index 15c9b7321..49abad60a 100644 --- a/src/value/hashable_value.rs +++ b/src/value/hashable_value.rs @@ -57,8 +57,6 @@ impl PartialEq for Value { (Self::JiffDateTime(l), Self::JiffDateTime(r)) => l == r, #[cfg(feature = "with-jiff")] (Self::JiffTimestamp(l), Self::JiffTimestamp(r)) => l == r, - #[cfg(feature = "with-jiff")] - (Self::JiffZoned(l), Self::JiffZoned(r)) => l == r, #[cfg(feature = "with-uuid")] (Self::Uuid(l), Self::Uuid(r)) => l == r, @@ -143,8 +141,6 @@ impl Hash for Value { Value::JiffDateTime(datetime) => datetime.hash(state), #[cfg(feature = "with-jiff")] Value::JiffTimestamp(timestamp) => timestamp.hash(state), - #[cfg(feature = "with-jiff")] - Value::JiffZoned(zoned) => zoned.hash(state), #[cfg(feature = "with-uuid")] Value::Uuid(uuid) => uuid.hash(state), diff --git a/src/value/postgres_array.rs b/src/value/postgres_array.rs index a47db20a8..713dc04ae 100644 --- a/src/value/postgres_array.rs +++ b/src/value/postgres_array.rs @@ -47,6 +47,18 @@ impl NotU8 for PrimitiveDateTime {} #[cfg(feature = "with-time")] impl NotU8 for OffsetDateTime {} +#[cfg(feature = "with-jiff")] +impl NotU8 for jiff::civil::Date {} + +#[cfg(feature = "with-jiff")] +impl NotU8 for jiff::civil::Time {} + +#[cfg(feature = "with-jiff")] +impl NotU8 for jiff::civil::DateTime {} + +#[cfg(feature = "with-jiff")] +impl NotU8 for jiff::Timestamp {} + #[cfg(feature = "with-rust_decimal")] impl NotU8 for Decimal {} diff --git a/src/value/prelude.rs b/src/value/prelude.rs index 660c004fc..97b044d95 100644 --- a/src/value/prelude.rs +++ b/src/value/prelude.rs @@ -8,7 +8,7 @@ pub use chrono::{self, DateTime, FixedOffset, Local, NaiveDate, NaiveDateTime, N pub use time::{self, OffsetDateTime, PrimitiveDateTime}; #[cfg(feature = "with-jiff")] -pub use jiff::{self, Timestamp, Zoned}; +pub use jiff::{self, Timestamp}; #[cfg(feature = "with-rust_decimal")] pub use rust_decimal::{self, Decimal}; diff --git a/src/value/with_jiff.rs b/src/value/with_jiff.rs index 80a188afb..f3d1dca9e 100644 --- a/src/value/with_jiff.rs +++ b/src/value/with_jiff.rs @@ -1,23 +1,20 @@ use super::*; -use jiff::{Timestamp, Zoned, civil}; +use jiff::{Timestamp, civil}; type_to_value!(civil::Date, JiffDate, Date); type_to_value!(civil::Time, JiffTime, Time); -type_to_box_value!(civil::DateTime, JiffDateTime, DateTime); -type_to_box_value!(Timestamp, JiffTimestamp, Timestamp); -type_to_box_value!(Zoned, JiffZoned, TimestampWithTimeZone); +type_to_box_value!(civil::DateTime, JiffDateTime, Timestamp); +type_to_box_value!(Timestamp, JiffTimestamp, TimestampWithTimeZone); impl DateLikeValue for civil::Date {} impl TimeLikeValue for civil::Time {} impl DateTimeLikeValue for civil::DateTime {} impl DateTimeLikeValue for Timestamp {} -impl DateTimeLikeValue for Zoned {} impl DateLikeValueNullable for Option {} impl TimeLikeValueNullable for Option {} impl DateTimeLikeValueNullable for Option {} impl DateTimeLikeValueNullable for Option {} -impl DateTimeLikeValueNullable for Option {} impl Value { #[inline] @@ -39,11 +36,6 @@ impl Value { pub fn jiff_timestamp>>(v: T) -> Value { Value::JiffTimestamp(v.into().map(Into::into)) } - - #[inline] - pub fn jiff_zoned>>(v: T) -> Value { - Value::JiffZoned(v.into().map(Into::into)) - } } impl Value { @@ -63,10 +55,6 @@ impl Value { matches!(self, Self::JiffTimestamp(_)) } - pub fn is_jiff_zoned(&self) -> bool { - matches!(self, Self::JiffZoned(_)) - } - pub fn as_ref_jiff_date(&self) -> Option<&civil::Date> { match self { Self::JiffDate(v) => v.as_ref(), @@ -94,76 +82,17 @@ impl Value { _ => panic!("not Value::JiffTimestamp"), } } - - pub fn as_ref_jiff_zoned(&self) -> Option<&Zoned> { - match self { - Self::JiffZoned(v) => v.as_deref(), - _ => panic!("not Value::JiffZoned"), - } - } } -pub(crate) const JIFF_DATE_TIME_FMT_STR: &str = "%Y-%m-%d %H:%M:%S%.6f"; -pub(crate) const JIFF_TIMESTAMP_FMT_STR: &str = "%Y-%m-%d %H:%M:%S%.6f"; -pub(crate) const JIFF_ZONE_FMT_STR: &str = "%Y-%m-%d %H:%M:%S%.6f %:z"; - impl Value { #[cfg(test)] pub(crate) fn jiff_value_to_string(&self) -> Option { match self { Self::JiffDate(v) => v.as_ref().map(|v| v.to_string()), Self::JiffTime(v) => v.as_ref().map(|v| v.to_string()), - Self::JiffDateTime(v) => v - .as_ref() - .map(|v| v.strftime(JIFF_DATE_TIME_FMT_STR).to_string()), - Self::JiffTimestamp(v) => v - .as_ref() - .map(|v| v.strftime(JIFF_TIMESTAMP_FMT_STR).to_string()), - Self::JiffZoned(v) => v - .as_ref() - .map(|v| v.strftime(JIFF_ZONE_FMT_STR).to_string()), + Self::JiffDateTime(v) => v.as_ref().map(|v| v.to_string()), + Self::JiffTimestamp(v) => v.as_ref().map(|v| v.to_string()), _ => panic!("not jiff Value"), } } } - -#[cfg(test)] -mod tests { - - use jiff::fmt::strtime; - - #[test] - fn jiff_fmt() { - use super::*; - assert_eq!( - Value::jiff_date(jiff::civil::date(2020, 1, 1)).jiff_value_to_string(), - Some("2020-01-01".to_owned()) - ); - assert_eq!( - Value::jiff_time(jiff::civil::time(1, 2, 3, 123456 * 1000)).jiff_value_to_string(), - Some("01:02:03.123456".to_owned()) - ); - assert_eq!( - Value::jiff_date_time(jiff::civil::date(2020, 1, 1).at(1, 2, 3, 123456 * 1000)) - .jiff_value_to_string(), - Some("2020-01-01 01:02:03.123456".to_owned()) - ); - - assert_eq!( - Value::jiff_timestamp(jiff::Timestamp::constant(0, 123456 * 1000)) - .jiff_value_to_string(), - Some("1970-01-01 00:00:00.123456".to_owned()) - ); - - assert_eq!( - Value::jiff_zoned( - strtime::parse(JIFF_ZONE_FMT_STR, "1970-01-01 00:00:00.123456 +00:00") - .unwrap() - .to_zoned() - .unwrap() - ) - .jiff_value_to_string(), - Some("1970-01-01 00:00:00.123456 +00:00".to_owned()) - ); - } -} diff --git a/src/value/with_json.rs b/src/value/with_json.rs index 62a4ec6f1..d252becf9 100644 --- a/src/value/with_json.rs +++ b/src/value/with_json.rs @@ -95,8 +95,6 @@ pub fn sea_value_to_json_value(value: &Value) -> Json { Value::JiffDateTime(_) => CommonSqlQueryBuilder.value_to_string(value).into(), #[cfg(feature = "with-jiff")] Value::JiffTimestamp(_) => CommonSqlQueryBuilder.value_to_string(value).into(), - #[cfg(feature = "with-jiff")] - Value::JiffZoned(_) => CommonSqlQueryBuilder.value_to_string(value).into(), #[cfg(feature = "with-rust_decimal")] Value::Decimal(Some(v)) => { use rust_decimal::prelude::ToPrimitive;