uqa_sql/ast/
composites.rs1use serde::{Deserialize, Serialize};
10use uqa_core::{
11 memory::{Produced, ProductionControl},
12 ValueRetentionError,
13};
14
15use super::ColumnType;
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct CreateCompositeType {
20 pub name: String,
22 pub attributes: Vec<CompositeAttributeDefinition>,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct CompositeAttributeDefinition {
28 pub name: String,
29 pub ty: ColumnType,
30 pub collation: Option<String>,
32 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
34 pub setof: bool,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct CompositeAttributeAddition {
40 pub attribute: CompositeAttributeDefinition,
41 pub declaration: super::ColumnDeclaration,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct CompositeAttributeRemoval {
47 pub name: String,
48 pub if_exists: bool,
49 pub cascade: bool,
50}
51
52#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
54#[serde(deny_unknown_fields)]
55pub struct CompositeRowBinding {
56 pub ty: String,
57 pub attributes: Vec<i16>,
58 #[serde(default, skip_serializing_if = "Option::is_none")]
60 pub argument_types: Option<Vec<ColumnType>>,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct CompositeTypeReference {
66 pub schema: String,
67 pub name: String,
68 pub oid: u32,
70 pub array_oid: u32,
71 pub relation_oid: u32,
73}
74
75impl PartialEq for CompositeTypeReference {
76 fn eq(&self, other: &Self) -> bool {
77 self.oid == other.oid
78 }
79}
80
81impl Eq for CompositeTypeReference {}
82
83impl CompositeTypeReference {
84 pub fn clone_with_control(
86 &self,
87 control: &ProductionControl<'_>,
88 ) -> Result<Produced<Self>, ValueRetentionError> {
89 let schema = control.copy_text(&self.schema)?;
90 let name = control.copy_text(&self.name)?;
91 let (schema, schema_memory) = schema.into_parts();
92 let (name, name_memory) = name.into_parts();
93 control.finish(
94 Self {
95 schema,
96 name,
97 oid: self.oid,
98 array_oid: self.array_oid,
99 relation_oid: self.relation_oid,
100 },
101 control.combine(schema_memory, name_memory),
102 )
103 }
104}