Skip to content
Draft
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
8 changes: 4 additions & 4 deletions crates/cornucopia/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
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,)> {
Expand All @@ -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 {
""
};
Expand Down Expand Up @@ -507,7 +507,7 @@ fn gen_query_fn<W: Write>(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| &param_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;
Expand Down Expand Up @@ -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 {
""
};
Expand Down
90 changes: 63 additions & 27 deletions test_codegen/src/cornucopia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1662,7 +1698,7 @@ pub mod queries {
pub arr: T4,
pub composite: Option<super::super::types::public::DomainCompositeParams<'a>>,
}
#[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,
Expand Down Expand Up @@ -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<String>,
pub json: Option<serde_json::Value>,
Expand Down Expand Up @@ -2224,11 +2260,11 @@ pub mod queries {
pub named: super::super::types::public::NamedCompositeBorrowed<'a>,
pub named_with_dot: Option<super::super::types::public::NamedCompositeWithDot>,
}
#[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,
Expand Down Expand Up @@ -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<super::super::types::public::NamedCompositeWithDot>,
Expand Down Expand Up @@ -2983,7 +3019,7 @@ pub mod queries {
pub name: T3,
pub composite: Option<super::super::types::public::NullityCompositeParams<'a>>,
}
#[derive(serde::Serialize, Debug, Clone, PartialEq)]
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)]
pub struct Nullity {
pub texts: Vec<Option<String>>,
pub name: String,
Expand Down Expand Up @@ -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<String>,
Expand All @@ -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<String>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<bool>,
pub boolean_: Option<bool>,
Expand Down Expand Up @@ -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<bool>,
pub boolean_: Vec<bool>,
Expand Down Expand Up @@ -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<Vec<bool>>,
pub boolean_: Option<Vec<bool>>,
Expand Down Expand Up @@ -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,
Expand Down