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 layout: Option<CompositeRowLayout>,
61 #[serde(default, skip_serializing_if = "Option::is_none")]
63 pub argument_types: Option<Vec<ColumnType>>,
64}
65
66#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
68#[serde(deny_unknown_fields)]
69pub struct CompositeRowLayout {
70 pub width: i16,
71 pub implicit: bool,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct CompositeTypeReference {
77 pub schema: String,
78 pub name: String,
79 pub oid: u32,
81 pub array_oid: u32,
82 pub relation_oid: u32,
84}
85
86impl PartialEq for CompositeTypeReference {
87 fn eq(&self, other: &Self) -> bool {
88 self.oid == other.oid
89 }
90}
91
92impl Eq for CompositeTypeReference {}
93
94impl CompositeTypeReference {
95 pub fn clone_with_control(
97 &self,
98 control: &ProductionControl<'_>,
99 ) -> Result<Produced<Self>, ValueRetentionError> {
100 let schema = control.copy_text(&self.schema)?;
101 let name = control.copy_text(&self.name)?;
102 let (schema, schema_memory) = schema.into_parts();
103 let (name, name_memory) = name.into_parts();
104 control.finish(
105 Self {
106 schema,
107 name,
108 oid: self.oid,
109 array_oid: self.array_oid,
110 relation_oid: self.relation_oid,
111 },
112 control.combine(schema_memory, name_memory),
113 )
114 }
115}