Skip to main content

sea_orm_spanner/
json_support.rs

1use {
2    gcloud_googleapis::spanner::v1::TypeCode,
3    gcloud_spanner::statement::{single_type, ToKind},
4    prost_types::value::Kind,
5};
6
7pub struct SpannerJson(pub serde_json::Value);
8
9impl SpannerJson {
10    pub fn new(value: serde_json::Value) -> Self {
11        Self(value)
12    }
13}
14
15impl ToKind for SpannerJson {
16    fn to_kind(&self) -> Kind {
17        Kind::StringValue(self.0.to_string())
18    }
19
20    fn get_type() -> gcloud_googleapis::spanner::v1::Type {
21        single_type(TypeCode::Json)
22    }
23}
24
25pub struct SpannerOptionalJson(pub Option<serde_json::Value>);
26
27impl SpannerOptionalJson {
28    pub fn some(value: serde_json::Value) -> Self {
29        Self(Some(value))
30    }
31
32    pub fn none() -> Self {
33        Self(None)
34    }
35}
36
37impl ToKind for SpannerOptionalJson {
38    fn to_kind(&self) -> Kind {
39        match &self.0 {
40            Some(v) => Kind::StringValue(v.to_string()),
41            None => Kind::NullValue(prost_types::NullValue::NullValue.into()),
42        }
43    }
44
45    fn get_type() -> gcloud_googleapis::spanner::v1::Type {
46        single_type(TypeCode::Json)
47    }
48}