diff --git a/sqlx-core/src/types.rs b/sqlx-core/src/types.rs index a519ffcf..8fcceb8a 100644 --- a/sqlx-core/src/types.rs +++ b/sqlx-core/src/types.rs @@ -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 diff --git a/sqlx-macros/src/backend/mod.rs b/sqlx-macros/src/backend/mod.rs index bbf8e921..3adba6cc 100644 --- a/sqlx-macros/src/backend/mod.rs +++ b/sqlx-macros/src/backend/mod.rs @@ -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) diff --git a/sqlx-macros/src/backend/postgres.rs b/sqlx-macros/src/backend/postgres.rs index 914d004c..d37a75ef 100644 --- a/sqlx-macros/src/backend/postgres.rs +++ b/sqlx-macros/src/backend/postgres.rs @@ -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::DateTime<_>, } }