cognite/dto/data_modeling/
containers.rs1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4use serde_with::skip_serializing_none;
5
6use crate::{
7 models::{TaggedContainerReference, UsedFor},
8 to_query, IntoParams, RawValue, SetCursor,
9};
10
11use super::common::{CDFExternalIdReference, EnumProperty, PrimitiveProperty, TextProperty};
12
13#[derive(Serialize, Deserialize, Clone, Debug)]
14#[serde(rename_all = "camelCase", tag = "type")]
15pub enum ContainerPropertyType {
17 Text(TextProperty),
19 Boolean(PrimitiveProperty),
21 Float32(PrimitiveProperty),
23 Float64(PrimitiveProperty),
25 Int32(PrimitiveProperty),
27 Int64(PrimitiveProperty),
29 Timestamp(PrimitiveProperty),
31 Date(PrimitiveProperty),
33 Json(PrimitiveProperty),
35 Timeseries(CDFExternalIdReference),
37 File(CDFExternalIdReference),
39 Sequence(CDFExternalIdReference),
41 Direct(DirectNodeRelationType),
43 Enum(EnumProperty),
45}
46
47#[skip_serializing_none]
48#[derive(Serialize, Deserialize, Clone, Debug, Default)]
49#[serde(rename_all = "camelCase")]
50pub struct DirectNodeRelationType {
52 pub container: Option<TaggedContainerReference>,
54}
55
56#[skip_serializing_none]
57#[derive(Serialize, Deserialize, Clone, Debug)]
58#[serde(
59 rename_all = "camelCase",
60 rename_all_fields = "camelCase",
61 tag = "constraintType"
62)]
63pub enum ContainerConstraint {
65 Requires {
69 require: TaggedContainerReference,
71 },
72 Uniqueness {
74 properties: Vec<String>,
76 },
77}
78
79#[skip_serializing_none]
80#[derive(Serialize, Deserialize, Clone, Debug)]
81#[serde(
82 rename_all = "camelCase",
83 rename_all_fields = "camelCase",
84 tag = "indexType"
85)]
86pub enum ContainerIndex {
88 Btree {
90 properties: Vec<String>,
92 cursorable: Option<bool>,
94 },
95 Inverted {
97 properties: Vec<String>,
99 },
100}
101
102#[skip_serializing_none]
103#[derive(Serialize, Deserialize, Clone, Debug)]
104#[serde(rename_all = "camelCase")]
105pub struct ContainerPropertyDefinition {
107 pub nullable: Option<bool>,
109 pub auto_increment: Option<bool>,
111 pub default_value: Option<RawValue>,
113 pub description: Option<String>,
115 pub name: Option<String>,
117 #[serde(rename = "type")]
118 pub r#type: ContainerPropertyType,
120}
121
122#[skip_serializing_none]
123#[derive(Serialize, Deserialize, Clone, Debug, Default)]
124#[serde(rename_all = "camelCase")]
125pub struct ContainerCreate {
127 pub space: String,
129 pub external_id: String,
131 pub name: Option<String>,
133 pub description: Option<String>,
135 pub used_for: Option<UsedFor>,
137 pub properties: HashMap<String, ContainerPropertyDefinition>,
139 pub constraints: HashMap<String, ContainerConstraint>,
141 pub indexes: HashMap<String, ContainerIndex>,
143}
144
145#[skip_serializing_none]
146#[derive(Serialize, Deserialize, Clone, Debug, Default)]
147#[serde(rename_all = "camelCase")]
148pub struct ContainerDefinition {
150 pub space: String,
152 pub external_id: String,
154 pub name: Option<String>,
156 pub description: Option<String>,
158 pub used_for: Option<UsedFor>,
160 pub properties: HashMap<String, ContainerPropertyDefinition>,
162 pub constraints: HashMap<String, ContainerConstraint>,
164 pub indexes: HashMap<String, ContainerIndex>,
166 pub created_time: i64,
168 pub last_updated_time: i64,
170 pub is_global: bool,
172}
173
174impl From<ContainerDefinition> for ContainerCreate {
175 fn from(value: ContainerDefinition) -> Self {
176 Self {
177 space: value.space,
178 external_id: value.external_id,
179 name: value.name,
180 description: value.description,
181 used_for: value.used_for,
182 properties: value.properties,
183 constraints: value.constraints,
184 indexes: value.indexes,
185 }
186 }
187}
188
189#[skip_serializing_none]
190#[derive(Serialize, Deserialize, Clone, Debug, Default)]
191#[serde(rename_all = "camelCase")]
192pub struct ContainerComponentId {
194 pub space: String,
196 pub container_external_id: String,
198 pub identifier: String,
200}
201
202#[derive(Default, Clone, Debug)]
203pub struct ContainerQuery {
205 pub limit: Option<i32>,
207 pub cursor: Option<String>,
209 pub space: Option<String>,
211 pub include_global: Option<bool>,
213}
214
215impl IntoParams for ContainerQuery {
216 fn into_params(self) -> Vec<(String, String)> {
217 let mut params = Vec::new();
218 to_query("limit", &self.limit, &mut params);
219 to_query("cursor", &self.cursor, &mut params);
220 to_query("space", &self.space, &mut params);
221 to_query("includeGlobal", &self.include_global, &mut params);
222 params
223 }
224}
225
226impl SetCursor for ContainerQuery {
227 fn set_cursor(&mut self, cursor: Option<String>) {
228 self.cursor = cursor;
229 }
230}