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

Fix #3748 #3752

Merged
merged 1 commit into from
Aug 18, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ jobs:
- name: Test diesel-derives (nightly)
if: matrix.rust == 'nightly'
shell: bash
run: cargo +${{ matrix.rust }} test --manifest-path diesel_derives/Cargo.toml --no-default-features --features "diesel/${{ matrix.backend }} diesel/unstable"
run: cargo +${{ matrix.rust }} test --manifest-path diesel_derives/Cargo.toml --no-default-features --features "diesel/${{ matrix.backend }} diesel/unstable diesel/time time diesel/chrono chrono"

- name: Test diesel-derives
shell: bash
Expand Down
2 changes: 2 additions & 0 deletions diesel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ returning_clauses_for_sqlite_3_35 = []
i-implement-a-third-party-backend-and-opt-into-breaking-changes = []
nightly-error-messages = []
r2d2 = ["diesel_derives/r2d2", "dep:r2d2"]
chrono = ["diesel_derives/chrono", "dep:chrono"]
time = ["diesel_derives/time", "dep:time"]

[package.metadata.docs.rs]
features = ["postgres", "mysql", "sqlite", "extras"]
Expand Down
8 changes: 8 additions & 0 deletions diesel/src/internal/derives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,12 @@ pub mod multiconnection {

#[doc(hidden)]
pub use crate::query_builder::select_statement::SelectStatementAccessor;

#[doc(hidden)]
#[cfg(feature = "chrono")]
pub use chrono;

#[doc(hidden)]
#[cfg(feature = "time")]
pub use time;
}
2 changes: 2 additions & 0 deletions diesel_derives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ mysql = []
without-deprecated = []
with-deprecated = []
r2d2 = []
chrono = []
time = []
72 changes: 64 additions & 8 deletions diesel_derives/src/multiconnection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ fn generate_row(connection_types: &[ConnectionVariant]) -> TokenStream {
}

fn generate_bind_collector(connection_types: &[ConnectionVariant]) -> TokenStream {
let to_sql_impls = vec![
let mut to_sql_impls = vec![
(
quote::quote!(diesel::sql_types::SmallInt),
quote::quote!(i16),
Expand All @@ -583,11 +583,40 @@ fn generate_bind_collector(connection_types: &[ConnectionVariant]) -> TokenStrea
quote::quote!([u8]),
),
(quote::quote!(diesel::sql_types::Bool), quote::quote!(bool)),
]
.into_iter()
.map(|t| generate_to_sql_impls(t, connection_types));
];
if cfg!(feature = "chrono") {
to_sql_impls.push((
quote::quote!(diesel::sql_types::Timestamp),
quote::quote!(diesel::internal::derives::multiconnection::chrono::NaiveDateTime),
));
to_sql_impls.push((
quote::quote!(diesel::sql_types::Date),
quote::quote!(diesel::internal::derives::multiconnection::chrono::NaiveDate),
));
to_sql_impls.push((
quote::quote!(diesel::sql_types::Time),
quote::quote!(diesel::internal::derives::multiconnection::chrono::NaiveTime),
));
}
if cfg!(feature = "time") {
to_sql_impls.push((
quote::quote!(diesel::sql_types::Timestamp),
quote::quote!(diesel::internal::derives::multiconnection::time::PrimitiveDateTime),
));
to_sql_impls.push((
quote::quote!(diesel::sql_types::Time),
quote::quote!(diesel::internal::derives::multiconnection::time::Time),
));
to_sql_impls.push((
quote::quote!(diesel::sql_types::Date),
quote::quote!(diesel::internal::derives::multiconnection::time::Date),
));
}
let to_sql_impls = to_sql_impls
.into_iter()
.map(|t| generate_to_sql_impls(t, connection_types));

let from_sql_impls = vec![
let mut from_sql_impls = vec![
(
quote::quote!(diesel::sql_types::SmallInt),
quote::quote!(i16),
Expand All @@ -608,9 +637,36 @@ fn generate_bind_collector(connection_types: &[ConnectionVariant]) -> TokenStrea
quote::quote!(Vec<u8>),
),
(quote::quote!(diesel::sql_types::Bool), quote::quote!(bool)),
]
.into_iter()
.map(generate_from_sql_impls);
];
if cfg!(feature = "chrono") {
from_sql_impls.push((
quote::quote!(diesel::sql_types::Timestamp),
quote::quote!(diesel::internal::derives::multiconnection::chrono::NaiveDateTime),
));
from_sql_impls.push((
quote::quote!(diesel::sql_types::Date),
quote::quote!(diesel::internal::derives::multiconnection::chrono::NaiveDate),
));
from_sql_impls.push((
quote::quote!(diesel::sql_types::Time),
quote::quote!(diesel::internal::derives::multiconnection::chrono::NaiveTime),
));
}
if cfg!(feature = "time") {
from_sql_impls.push((
quote::quote!(diesel::sql_types::Timestamp),
quote::quote!(diesel::internal::derives::multiconnection::time::PrimitiveDateTime),
));
from_sql_impls.push((
quote::quote!(diesel::sql_types::Time),
quote::quote!(diesel::internal::derives::multiconnection::time::Time),
));
from_sql_impls.push((
quote::quote!(diesel::sql_types::Date),
quote::quote!(diesel::internal::derives::multiconnection::time::Date),
));
}
let from_sql_impls = from_sql_impls.into_iter().map(generate_from_sql_impls);

let into_bind_value_bounds = connection_types.iter().map(|c| {
let ty = c.ty;
Expand Down
Loading
Loading