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, PartialEq, Eq, Serialize, Deserialize)]
46#[serde(deny_unknown_fields)]
47pub struct CompositeRowBinding {
48 pub ty: String,
49 pub attributes: Vec<i16>,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct CompositeTypeReference {
55 pub schema: String,
56 pub name: String,
57 pub oid: u32,
59 pub array_oid: u32,
60 pub relation_oid: u32,
62}
63
64impl PartialEq for CompositeTypeReference {
65 fn eq(&self, other: &Self) -> bool {
66 self.oid == other.oid
67 }
68}
69
70impl Eq for CompositeTypeReference {}
71
72impl CompositeTypeReference {
73 pub fn clone_with_control(
75 &self,
76 control: &ProductionControl<'_>,
77 ) -> Result<Produced<Self>, ValueRetentionError> {
78 let schema = control.copy_text(&self.schema)?;
79 let name = control.copy_text(&self.name)?;
80 let (schema, schema_memory) = schema.into_parts();
81 let (name, name_memory) = name.into_parts();
82 control.finish(
83 Self {
84 schema,
85 name,
86 oid: self.oid,
87 array_oid: self.array_oid,
88 relation_oid: self.relation_oid,
89 },
90 control.combine(schema_memory, name_memory),
91 )
92 }
93}