allow chrono to be used with query!()

This commit is contained in:
Austin Bonander 2019-12-13 18:04:15 -08:00 committed by Ryan Leckey
parent d8d93867b7
commit e11f5bcaa7
3 changed files with 21 additions and 6 deletions

View file

@ -1,6 +1,11 @@
#[cfg(feature = "uuid")]
pub use uuid::Uuid;
#[cfg(feature = "chrono")]
pub mod chrono {
pub use chrono::{NaiveDate, NaiveTime, NaiveDateTime, DateTime, Utc};
}
use std::fmt::Display;
/// Information about how a backend stores metadata about

View file

@ -13,7 +13,7 @@ pub trait BackendExt: Backend {
}
macro_rules! impl_backend_ext {
($backend:path { $($(#[$meta:meta])? $ty:ty $(| $borrowed:ty)?),* }) => {
($backend:path { $($(#[$meta:meta])? $ty:ty $(| $input:ty)?),*$(,)? }) => {
impl $crate::backend::BackendExt for $backend {
const BACKEND_PATH: &'static str = stringify!($backend);
@ -24,7 +24,7 @@ macro_rules! impl_backend_ext {
$(
// `if` statements cannot have attributes but these can
$(#[$meta])?
_ if <$backend as sqlx::types::HasSqlType<$ty>>::metadata().type_id_eq(id) => Some(borrowed_ty!($ty $(, $borrowed)?)),
_ if <$backend as sqlx::types::HasSqlType<$ty>>::metadata().type_id_eq(id) => Some(input_ty!($ty $(, $input)?)),
)*
_ => None
}
@ -45,9 +45,9 @@ macro_rules! impl_backend_ext {
}
}
macro_rules! borrowed_ty {
($ty:ty, $borrowed:ty) => {
stringify!($borrowed)
macro_rules! input_ty {
($ty:ty, $input:ty) => {
stringify!($input)
};
($ty:ty) => {
stringify!($ty)

View file

@ -7,7 +7,17 @@ impl_backend_ext! {
i64,
f32,
f64,
#[cfg(feature = "uuid")]
sqlx::types::Uuid
sqlx::types::Uuid,
#[cfg(feature = "chrono")]
sqlx::types::chrono::NaiveTime,
#[cfg(feature = "chrono")]
sqlx::types::chrono::NaiveDate,
#[cfg(feature = "chrono")]
sqlx::types::chrono::NaiveDateTime,
#[cfg(feature = "chrono")]
sqlx::types::chrono::DateTime<sqlx::types::chrono::Utc> | sqlx::types::chrono::DateTime<_>,
}
}