diff --git a/crates/cornucopia/src/codegen.rs b/crates/cornucopia/src/codegen.rs index af6c4b8a..2a94aeee 100644 --- a/crates/cornucopia/src/codegen.rs +++ b/crates/cornucopia/src/codegen.rs @@ -323,7 +323,7 @@ fn gen_params_struct(w: &mut impl Write, params: &PreparedItem, ctx: &GenCtx) { .map(|p| p.param_ergo_ty(traits, ctx)) .collect::>(); let fields_name = fields.iter().map(|p| &p.ident.rs); - let traits_idx = (1..=traits.len()).into_iter().map(idx_char); + let traits_idx = (1..=traits.len()).map(idx_char); code!(w => #[derive($copy Debug)] pub struct $name<$lifetime $($traits_idx: $traits,)> { @@ -347,7 +347,7 @@ fn gen_row_structs(w: &mut impl Write, row: &PreparedItem, ctx: &GenCtx) { let fields_ty = fields.iter().map(|p| p.own_struct(ctx)); let copy = if *is_copy { "Copy" } else { "" }; let ser_str = if ctx.gen_derive { - "serde::Serialize," + "serde::Serialize,serde::Deserialize," } else { "" }; @@ -507,7 +507,7 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu .map(|idx| param_field[*idx].param_ergo_ty(traits, ctx)) .collect(); let params_name = order.iter().map(|idx| ¶m_field[*idx].ident.rs); - let traits_idx = (1..=traits.len()).into_iter().map(idx_char); + let traits_idx = (1..=traits.len()).map(idx_char); let lazy_impl = |w: &mut W| { if let Some((idx, index)) = row { let item = module.rows.get_index(*idx).unwrap().1; @@ -647,7 +647,7 @@ fn gen_custom_type(w: &mut impl Write, schema: &str, prepared: &PreparedType, ct } = prepared; let copy = if *is_copy { "Copy," } else { "" }; let ser_str = if ctx.gen_derive { - "serde::Serialize," + "serde::Serialize,serde::Deserialize," } else { "" }; diff --git a/test_codegen/src/cornucopia.rs b/test_codegen/src/cornucopia.rs index 38df419d..05e56476 100644 --- a/test_codegen/src/cornucopia.rs +++ b/test_codegen/src/cornucopia.rs @@ -6,7 +6,9 @@ #[allow(dead_code)] pub mod types { pub mod public { - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] + #[derive( + serde::Serialize, serde::Deserialize, Debug, postgres_types :: FromSql, Clone, PartialEq, + )] #[postgres(name = "clone_composite")] pub struct CloneComposite { #[postgres(name = "first")] @@ -119,7 +121,15 @@ pub mod types { postgres_types::__to_sql_checked(self, ty, out) } } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Copy, Clone, PartialEq)] + #[derive( + serde::Serialize, + serde::Deserialize, + Debug, + postgres_types :: FromSql, + Copy, + Clone, + PartialEq, + )] #[postgres(name = "copy_composite")] pub struct CopyComposite { #[postgres(name = "first")] @@ -190,7 +200,9 @@ pub mod types { postgres_types::__to_sql_checked(self, ty, out) } } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] + #[derive( + serde::Serialize, serde::Deserialize, Debug, postgres_types :: FromSql, Clone, PartialEq, + )] #[postgres(name = "domain_composite")] pub struct DomainComposite { #[postgres(name = "txt")] @@ -352,7 +364,9 @@ pub mod types { postgres_types::__to_sql_checked(self, ty, out) } } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] + #[derive( + serde::Serialize, serde::Deserialize, Debug, postgres_types :: FromSql, Clone, PartialEq, + )] #[postgres(name = "named_composite")] pub struct NamedComposite { #[postgres(name = "wow")] @@ -465,7 +479,7 @@ pub mod types { postgres_types::__to_sql_checked(self, ty, out) } } - #[derive(serde::Serialize, Debug, Clone, Copy, PartialEq, Eq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Copy, PartialEq, Eq)] #[allow(non_camel_case_types)] pub enum EnumWithDot { variant_with_dot, @@ -537,7 +551,15 @@ pub mod types { } } } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Copy, Clone, PartialEq)] + #[derive( + serde::Serialize, + serde::Deserialize, + Debug, + postgres_types :: FromSql, + Copy, + Clone, + PartialEq, + )] #[postgres(name = "named_composite.with_dot")] pub struct NamedCompositeWithDot { #[postgres(name = "this.is.inconceivable")] @@ -612,7 +634,9 @@ pub mod types { postgres_types::__to_sql_checked(self, ty, out) } } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] + #[derive( + serde::Serialize, serde::Deserialize, Debug, postgres_types :: FromSql, Clone, PartialEq, + )] #[postgres(name = "nullity_composite")] pub struct NullityComposite { #[postgres(name = "jsons")] @@ -741,7 +765,7 @@ pub mod types { postgres_types::__to_sql_checked(self, ty, out) } } - #[derive(serde::Serialize, Debug, Clone, Copy, PartialEq, Eq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Copy, PartialEq, Eq)] #[allow(non_camel_case_types)] pub enum SpongebobCharacter { Bob, @@ -823,7 +847,9 @@ pub mod types { } } } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] + #[derive( + serde::Serialize, serde::Deserialize, Debug, postgres_types :: FromSql, Clone, PartialEq, + )] #[postgres(name = "custom_composite")] pub struct CustomComposite { #[postgres(name = "wow")] @@ -959,7 +985,9 @@ pub mod types { postgres_types::__to_sql_checked(self, ty, out) } } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] + #[derive( + serde::Serialize, serde::Deserialize, Debug, postgres_types :: FromSql, Clone, PartialEq, + )] #[postgres(name = "nightmare_composite")] pub struct NightmareComposite { #[postgres(name = "custom")] @@ -1106,7 +1134,15 @@ pub mod types { postgres_types::__to_sql_checked(self, ty, out) } } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Copy, Clone, PartialEq)] + #[derive( + serde::Serialize, + serde::Deserialize, + Debug, + postgres_types :: FromSql, + Copy, + Clone, + PartialEq, + )] #[postgres(name = "syntax_composite")] pub struct SyntaxComposite { #[postgres(name = "async")] @@ -1173,7 +1209,7 @@ pub mod types { postgres_types::__to_sql_checked(self, ty, out) } } - #[derive(serde::Serialize, Debug, Clone, Copy, PartialEq, Eq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Copy, PartialEq, Eq)] #[allow(non_camel_case_types)] pub enum SyntaxEnum { r#async, @@ -1662,7 +1698,7 @@ pub mod queries { pub arr: T4, pub composite: Option>, } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] pub struct SelectNightmareDomain { pub txt: String, pub json: serde_json::Value, @@ -1694,7 +1730,7 @@ pub mod queries { } } } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] pub struct SelectNightmareDomainNull { pub txt: Option, pub json: Option, @@ -2224,11 +2260,11 @@ pub mod queries { pub named: super::super::types::public::NamedCompositeBorrowed<'a>, pub named_with_dot: Option, } - #[derive(serde::Serialize, Debug, Clone, PartialEq, Copy)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Copy)] pub struct Id { pub id: i32, } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] pub struct Named { pub id: i32, pub name: String, @@ -2258,7 +2294,7 @@ pub mod queries { } } } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] pub struct NamedComplex { pub named: super::super::types::public::NamedComposite, pub named_with_dot: Option, @@ -2983,7 +3019,7 @@ pub mod queries { pub name: T3, pub composite: Option>, } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] pub struct Nullity { pub texts: Vec>, pub name: String, @@ -3292,7 +3328,7 @@ pub mod queries { pub c: i32, pub a: i32, } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] pub struct SelectBook { pub name: String, pub author: Option, @@ -3309,7 +3345,7 @@ pub mod queries { } } } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] pub struct FindBooks { pub name: String, pub author: Option, @@ -3964,7 +4000,7 @@ pub mod queries { pub macaddr_: T32, pub numeric_: T33, } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] pub struct Everything { pub bool_: bool, pub boolean_: bool, @@ -4114,7 +4150,7 @@ pub mod queries { } } } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] pub struct EverythingNull { pub bool_: Option, pub boolean_: Option, @@ -4264,7 +4300,7 @@ pub mod queries { } } } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] pub struct EverythingArray { pub bool_: Vec, pub boolean_: Vec, @@ -4402,7 +4438,7 @@ pub mod queries { } } } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] pub struct EverythingArrayNull { pub bool_: Option>, pub boolean_: Option>, @@ -6552,15 +6588,15 @@ FROM pub r#async: super::super::types::public::SyntaxComposite, pub r#enum: super::super::types::public::SyntaxEnum, } - #[derive(serde::Serialize, Debug, Clone, PartialEq, Copy)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Copy)] pub struct Row { pub id: i32, } - #[derive(serde::Serialize, Debug, Clone, PartialEq, Copy)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Copy)] pub struct RowSpace { pub id: i32, } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] pub struct Typeof { pub trick_y: String, pub r#async: super::super::types::public::SyntaxComposite,