diff options
Diffstat (limited to 'tosin-macros')
-rw-r--r-- | tosin-macros/src/lib.rs | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/tosin-macros/src/lib.rs b/tosin-macros/src/lib.rs index 15a0266..0da725e 100644 --- a/tosin-macros/src/lib.rs +++ b/tosin-macros/src/lib.rs @@ -77,8 +77,8 @@ fn to_field_spec(field: &syn::Field) -> FieldInfo<impl quote::ToTokens> { if field_type == &parse_type("Option<Id>") { FieldInfo { tosin_field: quote! { ::tosin::db::models::Field::IntField { name: stringify!(#field_name) } }, - diesel_column: quote! { #field_name -> Integer }, - diesel_type: quote! { ::tosin::db::sql_types::Integer }, + diesel_column: quote! { #field_name -> BigInt }, + diesel_type: quote! { ::tosin::db::sql_types::BigInt }, } } else if field_type == &parse_type("Id") { // TODO foreign key constraint @@ -132,7 +132,22 @@ fn impl_model(ast: &syn::DeriveInput) -> TokenStream { } else { panic!("not on a struct"); }; - let real_types: Vec<_> = ast_data.fields.iter().map(|field| &field.ty).collect(); + let real_db_types: Vec<_> = ast_data + .fields + .iter() + .map(|field| { + if field + .ident + .as_ref() + .map_or(false, |name| name.to_string() == "id") + && field.ty == syn::parse_str("Option<Id>").unwrap() + { + syn::parse_str("Id").unwrap() + } else { + field.ty.clone() + } + }) + .collect(); let FieldsInfo { tosin_fields, diesel_columns, @@ -147,11 +162,11 @@ fn impl_model(ast: &syn::DeriveInput) -> TokenStream { } impl<__DB: tosin::db::diesel_backend::Backend, __ST> tosin::db::Queryable<__ST, __DB> for #name - where (#(#real_types),*): tosin::db::Queryable<__ST, __DB> { - type Row = <(#(#real_types),*) as tosin::db::Queryable<__ST, __DB>>::Row; + where (#(#real_db_types),*): tosin::db::Queryable<__ST, __DB> { + type Row = <(#(#real_db_types),*) as tosin::db::Queryable<__ST, __DB>>::Row; fn build(row: Self::Row) -> Self { - let row: (#(#real_types),*) = tosin::db::Queryable::build(row); + let row: (#(#real_db_types),*) = tosin::db::Queryable::build(row); todo!() } } |