Skip to main content

sea_orm_spanner/
array_support.rs

1use {
2    gcloud_googleapis::spanner::v1::{Type, TypeAnnotationCode, TypeCode},
3    gcloud_spanner::statement::ToKind,
4    prost_types::{value, ListValue, Value},
5};
6
7pub struct SpannerInt64Array(pub Vec<i64>);
8
9impl ToKind for SpannerInt64Array {
10    fn to_kind(&self) -> value::Kind {
11        value::Kind::ListValue(ListValue {
12            values: self
13                .0
14                .iter()
15                .map(|x| Value {
16                    kind: Some(x.to_string().to_kind()),
17                })
18                .collect(),
19        })
20    }
21
22    fn get_type() -> Type {
23        Type {
24            code: TypeCode::Array.into(),
25            array_element_type: Some(Box::new(Type {
26                code: TypeCode::Int64.into(),
27                array_element_type: None,
28                struct_type: None,
29                type_annotation: TypeAnnotationCode::Unspecified.into(),
30                proto_type_fqn: String::new(),
31            })),
32            struct_type: None,
33            type_annotation: TypeAnnotationCode::Unspecified.into(),
34            proto_type_fqn: String::new(),
35        }
36    }
37}
38
39pub struct SpannerOptionalInt64Array(pub Option<Vec<i64>>);
40
41impl SpannerOptionalInt64Array {
42    pub fn some(v: Vec<i64>) -> Self {
43        Self(Some(v))
44    }
45
46    pub fn none() -> Self {
47        Self(None)
48    }
49}
50
51impl ToKind for SpannerOptionalInt64Array {
52    fn to_kind(&self) -> value::Kind {
53        match &self.0 {
54            Some(v) => SpannerInt64Array(v.clone()).to_kind(),
55            None => value::Kind::NullValue(prost_types::NullValue::NullValue.into()),
56        }
57    }
58
59    fn get_type() -> Type {
60        SpannerInt64Array::get_type()
61    }
62}
63
64pub struct SpannerFloat64Array(pub Vec<f64>);
65
66impl ToKind for SpannerFloat64Array {
67    fn to_kind(&self) -> value::Kind {
68        value::Kind::ListValue(ListValue {
69            values: self
70                .0
71                .iter()
72                .map(|x| Value {
73                    kind: Some(value::Kind::NumberValue(*x)),
74                })
75                .collect(),
76        })
77    }
78
79    fn get_type() -> Type {
80        Type {
81            code: TypeCode::Array.into(),
82            array_element_type: Some(Box::new(Type {
83                code: TypeCode::Float64.into(),
84                array_element_type: None,
85                struct_type: None,
86                type_annotation: TypeAnnotationCode::Unspecified.into(),
87                proto_type_fqn: String::new(),
88            })),
89            struct_type: None,
90            type_annotation: TypeAnnotationCode::Unspecified.into(),
91            proto_type_fqn: String::new(),
92        }
93    }
94}
95
96pub struct SpannerOptionalFloat64Array(pub Option<Vec<f64>>);
97
98impl SpannerOptionalFloat64Array {
99    pub fn some(v: Vec<f64>) -> Self {
100        Self(Some(v))
101    }
102
103    pub fn none() -> Self {
104        Self(None)
105    }
106}
107
108impl ToKind for SpannerOptionalFloat64Array {
109    fn to_kind(&self) -> value::Kind {
110        match &self.0 {
111            Some(v) => SpannerFloat64Array(v.clone()).to_kind(),
112            None => value::Kind::NullValue(prost_types::NullValue::NullValue.into()),
113        }
114    }
115
116    fn get_type() -> Type {
117        SpannerFloat64Array::get_type()
118    }
119}
120
121pub struct SpannerStringArray(pub Vec<String>);
122
123impl ToKind for SpannerStringArray {
124    fn to_kind(&self) -> value::Kind {
125        value::Kind::ListValue(ListValue {
126            values: self
127                .0
128                .iter()
129                .map(|x| Value {
130                    kind: Some(value::Kind::StringValue(x.clone())),
131                })
132                .collect(),
133        })
134    }
135
136    fn get_type() -> Type {
137        Type {
138            code: TypeCode::Array.into(),
139            array_element_type: Some(Box::new(Type {
140                code: TypeCode::String.into(),
141                array_element_type: None,
142                struct_type: None,
143                type_annotation: TypeAnnotationCode::Unspecified.into(),
144                proto_type_fqn: String::new(),
145            })),
146            struct_type: None,
147            type_annotation: TypeAnnotationCode::Unspecified.into(),
148            proto_type_fqn: String::new(),
149        }
150    }
151}
152
153pub struct SpannerOptionalStringArray(pub Option<Vec<String>>);
154
155impl SpannerOptionalStringArray {
156    pub fn some(v: Vec<String>) -> Self {
157        Self(Some(v))
158    }
159
160    pub fn none() -> Self {
161        Self(None)
162    }
163}
164
165impl ToKind for SpannerOptionalStringArray {
166    fn to_kind(&self) -> value::Kind {
167        match &self.0 {
168            Some(v) => SpannerStringArray(v.clone()).to_kind(),
169            None => value::Kind::NullValue(prost_types::NullValue::NullValue.into()),
170        }
171    }
172
173    fn get_type() -> Type {
174        SpannerStringArray::get_type()
175    }
176}
177
178pub struct SpannerBoolArray(pub Vec<bool>);
179
180impl ToKind for SpannerBoolArray {
181    fn to_kind(&self) -> value::Kind {
182        value::Kind::ListValue(ListValue {
183            values: self
184                .0
185                .iter()
186                .map(|x| Value {
187                    kind: Some(value::Kind::BoolValue(*x)),
188                })
189                .collect(),
190        })
191    }
192
193    fn get_type() -> Type {
194        Type {
195            code: TypeCode::Array.into(),
196            array_element_type: Some(Box::new(Type {
197                code: TypeCode::Bool.into(),
198                array_element_type: None,
199                struct_type: None,
200                type_annotation: TypeAnnotationCode::Unspecified.into(),
201                proto_type_fqn: String::new(),
202            })),
203            struct_type: None,
204            type_annotation: TypeAnnotationCode::Unspecified.into(),
205            proto_type_fqn: String::new(),
206        }
207    }
208}
209
210pub struct SpannerOptionalBoolArray(pub Option<Vec<bool>>);
211
212impl SpannerOptionalBoolArray {
213    pub fn some(v: Vec<bool>) -> Self {
214        Self(Some(v))
215    }
216
217    pub fn none() -> Self {
218        Self(None)
219    }
220}
221
222impl ToKind for SpannerOptionalBoolArray {
223    fn to_kind(&self) -> value::Kind {
224        match &self.0 {
225            Some(v) => SpannerBoolArray(v.clone()).to_kind(),
226            None => value::Kind::NullValue(prost_types::NullValue::NullValue.into()),
227        }
228    }
229
230    fn get_type() -> Type {
231        SpannerBoolArray::get_type()
232    }
233}
234
235pub struct SpannerBytesArray(pub Vec<Vec<u8>>);
236
237impl ToKind for SpannerBytesArray {
238    fn to_kind(&self) -> value::Kind {
239        value::Kind::ListValue(ListValue {
240            values: self
241                .0
242                .iter()
243                .map(|x| Value {
244                    kind: Some(value::Kind::StringValue(base64::encode(x))),
245                })
246                .collect(),
247        })
248    }
249
250    fn get_type() -> Type {
251        Type {
252            code: TypeCode::Array.into(),
253            array_element_type: Some(Box::new(Type {
254                code: TypeCode::Bytes.into(),
255                array_element_type: None,
256                struct_type: None,
257                type_annotation: TypeAnnotationCode::Unspecified.into(),
258                proto_type_fqn: String::new(),
259            })),
260            struct_type: None,
261            type_annotation: TypeAnnotationCode::Unspecified.into(),
262            proto_type_fqn: String::new(),
263        }
264    }
265}
266
267pub struct SpannerOptionalBytesArray(pub Option<Vec<Vec<u8>>>);
268
269impl SpannerOptionalBytesArray {
270    pub fn some(v: Vec<Vec<u8>>) -> Self {
271        Self(Some(v))
272    }
273
274    pub fn none() -> Self {
275        Self(None)
276    }
277}
278
279impl ToKind for SpannerOptionalBytesArray {
280    fn to_kind(&self) -> value::Kind {
281        match &self.0 {
282            Some(v) => SpannerBytesArray(v.clone()).to_kind(),
283            None => value::Kind::NullValue(prost_types::NullValue::NullValue.into()),
284        }
285    }
286
287    fn get_type() -> Type {
288        SpannerBytesArray::get_type()
289    }
290}