Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues-280 Fix driver for work with types #287

Closed
Closed
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
18 changes: 7 additions & 11 deletions src/backend/query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,28 +1026,24 @@ pub trait QueryBuilder: QuotedBuilder {
#[cfg(feature = "with-json")]
Value::Json(Some(v)) => self.write_string_quoted(&v.to_string(), &mut s),
#[cfg(feature = "with-chrono")]
Value::ChronoDate(Some(v)) => {
write!(s, "\'{}\'", v.format("%Y-%m-%d").to_string()).unwrap()
}
Value::ChronoDate(Some(v)) => write!(s, "\'{}\'", v.format("%Y-%m-%d")).unwrap(),
#[cfg(feature = "with-chrono")]
Value::ChronoTime(Some(v)) => {
write!(s, "\'{}\'", v.format("%H:%M:%S").to_string()).unwrap()
}
Value::ChronoTime(Some(v)) => write!(s, "\'{}\'", v.format("%H:%M:%S")).unwrap(),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTime(Some(v)) => {
write!(s, "\'{}\'", v.format("%Y-%m-%d %H:%M:%S").to_string()).unwrap()
write!(s, "\'{}\'", v.format("%Y-%m-%d %H:%M:%S")).unwrap()
}
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeUtc(Some(v)) => {
write!(s, "\'{}\'", v.format("%Y-%m-%d %H:%M:%S %:z").to_string()).unwrap()
write!(s, "\'{}\'", v.format("%Y-%m-%d %H:%M:%S %:z")).unwrap()
}
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeLocal(Some(v)) => {
write!(s, "\'{}\'", v.format("%Y-%m-%d %H:%M:%S %:z").to_string()).unwrap()
write!(s, "\'{}\'", v.format("%Y-%m-%d %H:%M:%S %:z")).unwrap()
}
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeWithTimeZone(Some(v)) => {
write!(s, "\'{}\'", v.format("%Y-%m-%d %H:%M:%S %:z").to_string()).unwrap()
write!(s, "\'{}\'", v.format("%Y-%m-%d %H:%M:%S %:z")).unwrap()
}
#[cfg(feature = "with-time")]
Value::TimeDate(Some(v)) => write!(s, "\'{}\'", v.format("%Y-%m-%d")).unwrap(),
Expand All @@ -1066,7 +1062,7 @@ pub trait QueryBuilder: QuotedBuilder {
#[cfg(feature = "with-bigdecimal")]
Value::BigDecimal(Some(v)) => write!(s, "{}", v).unwrap(),
#[cfg(feature = "with-uuid")]
Value::Uuid(Some(v)) => write!(s, "\'{}\'", v.to_string()).unwrap(),
Value::Uuid(Some(v)) => write!(s, "\'{}\'", v).unwrap(),
#[cfg(feature = "postgres-array")]
Value::Array(Some(v)) => write!(
s,
Expand Down
54 changes: 25 additions & 29 deletions src/driver/rusqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,31 @@ macro_rules! sea_query_driver_rusqlite {
Value::Double(v) => to_sql!(v, f64),
Value::String(v) => box_to_sql!(v, String),
Value::Bytes(v) => box_to_sql!(v, Vec<u8>),
_ => {
if self.0.is_json() {
ty_to_sql!(self.0.as_ref_json())
} else if self.0.is_chrono_date() {
ty_to_sql!(self.0.as_ref_chrono_date())
} else if self.0.is_chrono_time() {
ty_to_sql!(self.0.as_ref_chrono_time())
} else if self.0.is_chrono_date_time() {
ty_to_sql!(self.0.as_ref_chrono_date_time())
} else if self.0.is_chrono_date_time_utc() {
ty_to_sql!(self.0.as_ref_chrono_date_time_utc())
} else if self.0.is_chrono_date_time_local() {
ty_to_sql!(self.0.as_ref_chrono_date_time_local())
} else if self.0.is_chrono_date_time_with_time_zone() {
ty_to_sql!(self.0.as_ref_chrono_date_time_with_time_zone())
} else if self.0.is_time_date() {
opt_string_to_sql!(self.0.time_as_naive_utc_in_string())
} else if self.0.is_time_time() {
opt_string_to_sql!(self.0.time_as_naive_utc_in_string())
} else if self.0.is_time_date_time() {
opt_string_to_sql!(self.0.time_as_naive_utc_in_string())
} else if self.0.is_time_date_time_with_time_zone() {
ty_to_sql!(self.0.as_ref_time_date_time_with_time_zone())
} else if self.0.is_uuid() {
ty_to_sql!(self.0.as_ref_uuid())
} else {
unimplemented!();
}
}
#[cfg(feature = "with-json")]
Value::Json(v) => ty_to_sql!(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDate(v) => ty_to_sql!(v),
#[cfg(feature = "with-chrono")]
Value::ChronoTime(v) => ty_to_sql!(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTime(v) => ty_to_sql!(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeUtc(v) => ty_to_sql!(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeLocal(v) => ty_to_sql!(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeWithTimeZone(v) => ty_to_sql!(v),
#[cfg(feature = "with-time")]
Value::TimeDate(v) => opt_string_to_sql!(v),
#[cfg(feature = "with-time")]
Value::TimeTime(v) => opt_string_to_sql!(v),
#[cfg(feature = "with-time")]
Value::TimeDateTime(v) => opt_string_to_sql!(v),
#[cfg(feature = "with-time")]
Value::TimeDateTimeWithTimeZone(v) => opt_string_to_sql!(v),
#[cfg(feature = "with-uuid")]
Value::Uuid(v) => ty_to_sql!(v),
_ => unimplemented!(),
}
}
}
Expand Down
62 changes: 29 additions & 33 deletions src/driver/sqlx_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,35 @@ macro_rules! bind_params_sqlx_mysql {
Value::Double(v) => bind!(v, f64),
Value::String(v) => bind_box!(v, String),
Value::Bytes(v) => bind_box!(v, Vec<u8>),
_ => {
if value.is_json() {
query.bind(value.as_ref_json())
} else if value.is_chrono_date() {
query.bind(value.as_ref_chrono_date())
} else if value.is_chrono_time() {
query.bind(value.as_ref_chrono_time())
} else if value.is_chrono_date_time() {
query.bind(value.as_ref_chrono_date_time())
} else if value.is_chrono_date_time_utc() {
query.bind(value.as_ref_chrono_date_time_utc())
} else if value.is_chrono_date_time_local() {
query.bind(value.as_ref_chrono_date_time_local())
} else if value.is_chrono_date_time_with_time_zone() {
query.bind(value.chrono_as_naive_utc_in_string())
} else if value.is_time_date() {
query.bind(value.as_ref_time_date())
} else if value.is_time_time() {
query.bind(value.as_ref_time_time())
} else if value.is_time_date_time() {
query.bind(value.as_ref_time_date_time())
} else if value.is_time_date_time_with_time_zone() {
query.bind(value.time_as_naive_utc_in_string())
} else if value.is_decimal() {
query.bind(value.as_ref_decimal())
} else if value.is_big_decimal() {
query.bind(value.as_ref_big_decimal())
} else if value.is_uuid() {
query.bind(value.as_ref_uuid())
} else {
unimplemented!();
}
}
#[cfg(feature = "with-json")]
Value::Json(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDate(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoTime(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTime(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeUtc(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeLocal(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeWithTimeZone(v) => query.bind(v),
#[cfg(feature = "with-time")]
Value::TimeDate(v) => query.bind(v),
#[cfg(feature = "with-time")]
Value::TimeTime(v) => query.bind(v),
#[cfg(feature = "with-time")]
Value::TimeDateTime(v) => query.bind(v),
#[cfg(feature = "with-time")]
Value::TimeDateTimeWithTimeZone(v) => query.bind(v),
#[cfg(feature = "with-uuid")]
Value::Uuid(v) => query.bind(v),
#[cfg(feature = "with-rust_decimal")]
Value::Decimal(v) => query.bind(v),
#[cfg(feature = "with-bigdecimal")]
Value::BigDecimal(v) => query.bind(v),
_ => unimplemented!(),
};
}
query
Expand Down
67 changes: 32 additions & 35 deletions src/driver/sqlx_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,38 @@ macro_rules! bind_params_sqlx_postgres {
Value::Double(v) => bind!(v, f64),
Value::String(v) => bind_box!(v, String),
Value::Bytes(v) => bind_box!(v, Vec<u8>),
_ => {
if value.is_json() {
query.bind(value.as_ref_json())
} else if value.is_chrono_date() {
query.bind(value.as_ref_chrono_date())
} else if value.is_chrono_time() {
query.bind(value.as_ref_chrono_time())
} else if value.is_chrono_date_time() {
query.bind(value.as_ref_chrono_date_time())
} else if value.is_chrono_date_time_utc() {
query.bind(value.as_ref_chrono_date_time_utc())
} else if value.is_chrono_date_time_local() {
query.bind(value.as_ref_chrono_date_time_local())
} else if value.is_chrono_date_time_with_time_zone() {
query.bind(value.as_ref_chrono_date_time_with_time_zone())
} else if value.is_time_date() {
query.bind(value.as_ref_time_date())
} else if value.is_time_time() {
query.bind(value.as_ref_time_time())
} else if value.is_time_date_time() {
query.bind(value.as_ref_time_date_time())
} else if value.is_time_date_time_with_time_zone() {
query.bind(value.as_ref_time_date_time_with_time_zone())
} else if value.is_decimal() {
query.bind(value.as_ref_decimal())
} else if value.is_big_decimal() {
query.bind(value.as_ref_big_decimal())
} else if value.is_uuid() {
query.bind(value.as_ref_uuid())
} else if value.is_array() {
unimplemented!("SQLx array is not supported");
} else {
unimplemented!();
}
}
#[cfg(feature = "with-json")]
Value::Json(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDate(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoTime(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTime(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeUtc(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeLocal(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeWithTimeZone(v) => query.bind(v),
#[cfg(feature = "with-time")]
Value::TimeDate(v) => query.bind(v),
#[cfg(feature = "with-time")]
Value::TimeTime(v) => query.bind(v),
#[cfg(feature = "with-time")]
Value::TimeDateTime(v) => query.bind(v),
#[cfg(feature = "with-time")]
Value::TimeDateTimeWithTimeZone(v) => query.bind(v),
#[cfg(feature = "with-uuid")]
Value::Uuid(v) => query.bind(v),
#[cfg(feature = "with-rust_decimal")]
Value::Decimal(v) => query.bind(v),
#[cfg(feature = "with-bigdecimal")]
Value::BigDecimal(v) => query.bind(v),
#[cfg(feature = "postgres-array")]
Value::Array(_) => unimplemented!("SQLx array is not supported"),
#[allow(unreachable_patterns)]
_ => unimplemented!(),
};
}
query
Expand Down
62 changes: 29 additions & 33 deletions src/driver/sqlx_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,35 @@ macro_rules! bind_params_sqlx_sqlite {
Value::Double(v) => bind!(v, f64),
Value::String(v) => bind_box!(v, String),
Value::Bytes(v) => bind_box!(v, Vec<u8>),
_ => {
if value.is_json() {
query.bind(value.as_ref_json())
} else if value.is_chrono_date() {
query.bind(value.as_ref_chrono_date())
} else if value.is_chrono_time() {
query.bind(value.as_ref_chrono_time())
} else if value.is_chrono_date_time() {
query.bind(value.as_ref_chrono_date_time())
} else if value.is_chrono_date_time_utc() {
query.bind(value.chrono_as_naive_utc_in_string())
} else if value.is_chrono_date_time_local() {
query.bind(value.chrono_as_naive_utc_in_string())
} else if value.is_chrono_date_time_with_time_zone() {
query.bind(value.chrono_as_naive_utc_in_string())
} else if value.is_time_date() {
query.bind(value.time_as_naive_utc_in_string())
} else if value.is_time_time() {
query.bind(value.time_as_naive_utc_in_string())
} else if value.is_time_date_time() {
query.bind(value.time_as_naive_utc_in_string())
} else if value.is_time_date_time_with_time_zone() {
query.bind(value.time_as_naive_utc_in_string())
} else if value.is_decimal() {
query.bind(value.decimal_to_f64())
} else if value.is_big_decimal() {
query.bind(value.big_decimal_to_f64())
} else if value.is_uuid() {
query.bind(value.as_ref_uuid())
} else {
unimplemented!();
}
}
#[cfg(feature = "with-json")]
Value::Json(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDate(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoTime(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTime(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeUtc(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeLocal(v) => query.bind(v),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeWithTimeZone(v) => query.bind(v),
#[cfg(feature = "with-time")]
Value::TimeDate(v) => query.bind(v),
#[cfg(feature = "with-time")]
Value::TimeTime(v) => query.bind(v),
#[cfg(feature = "with-time")]
Value::TimeDateTime(v) => query.bind(v),
#[cfg(feature = "with-time")]
Value::TimeDateTimeWithTimeZone(v) => query.bind(v),
#[cfg(feature = "with-uuid")]
Value::Uuid(v) => query.bind(v),
#[cfg(feature = "with-rust_decimal")]
Value::Decimal(v) => query.bind(v),
#[cfg(feature = "with-bigdecimal")]
Value::BigDecimal(v) => query.bind(v),
_ => unimplemented!(),
};
}
query
Expand Down
Loading