Skip to content

Commit

Permalink
Merge pull request diesel-rs#3721 from weiznich/fix/3719
Browse files Browse the repository at this point in the history
  • Loading branch information
weiznich committed Aug 15, 2023
1 parent 2d775af commit eeb46ce
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion diesel_derives/src/selectable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn derive(item: DeriveInput) -> Result<TokenStream> {
.filter(|(f, _)| !f.embed())
.flat_map(|(f, ty)| {
backends.iter().map(move |b| {
let field_ty = to_field_ty_bound(&f.ty);
let field_ty = to_field_ty_bound(f.ty_for_deserialize());
let span = field_ty.span();
quote::quote_spanned! {span =>
#field_ty: diesel::deserialize::FromSqlRow<diesel::dsl::SqlTypeOf<#ty>, #b>
Expand Down
3 changes: 3 additions & 0 deletions diesel_derives/tests/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use diesel::prelude::*;
use diesel::sql_query;

#[allow(dead_code)] // that's used in one of the compile tests
pub type TestBackend = <TestConnection as diesel::Connection>::Backend;

cfg_if! {
if #[cfg(feature = "sqlite")] {
pub type TestConnection = SqliteConnection;
Expand Down
27 changes: 27 additions & 0 deletions diesel_derives/tests/selectable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,30 @@ fn manually_specified_expression() {
let data = my_structs::table.select(A::as_select()).get_result(conn);
assert!(data.is_err());
}

#[allow(dead_code)] // that's essentially a compile test
#[test]
fn check_for_backend_with_deserialize_as() {
table! {
tests {
id -> Integer,
name -> Text,
}
}

struct MyString(String);

impl From<String> for MyString {
fn from(s: String) -> Self {
Self(s)
}
}

#[derive(Queryable, Selectable)]
#[diesel(check_for_backend(crate::helpers::TestBackend))]
struct Test {
id: i32,
#[diesel(deserialize_as = String)]
name: MyString,
}
}

0 comments on commit eeb46ce

Please sign in to comment.