cognite/dto/data_modeling/
data_models.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use crate::{
5    models::views::{ViewCreateOrReference, ViewDefinitionOrReference},
6    to_query, IntoParams, SetCursor,
7};
8
9#[skip_serializing_none]
10#[derive(Serialize, Deserialize, Clone, Debug, Default)]
11#[serde(rename_all = "camelCase")]
12/// Create a data model.
13pub struct DataModelCreate {
14    /// Data model space.
15    pub space: String,
16    /// Data model external ID.
17    pub external_id: String,
18    /// Data model name.
19    pub name: Option<String>,
20    /// Data model description.
21    pub description: Option<String>,
22    /// Data model version.
23    pub version: String,
24    /// Views in data model.
25    pub views: Option<Vec<ViewCreateOrReference>>,
26}
27
28impl From<DataModel> for DataModelCreate {
29    fn from(value: DataModel) -> Self {
30        DataModelCreate {
31            space: value.space,
32            external_id: value.external_id,
33            name: value.name,
34            description: value.description,
35            version: value.version,
36            views: value
37                .views
38                .map(|views| views.into_iter().map(|v| v.into()).collect()),
39        }
40    }
41}
42
43#[skip_serializing_none]
44#[derive(Serialize, Deserialize, Clone, Debug, Default)]
45#[serde(rename_all = "camelCase")]
46/// A CDF data model.
47pub struct DataModel {
48    /// Data model space.
49    pub space: String,
50    /// Data model external ID.
51    pub external_id: String,
52    /// Data model name.
53    pub name: Option<String>,
54    /// Data model description.
55    pub description: Option<String>,
56    /// Data model version.
57    pub version: String,
58    /// Views in data model.
59    pub views: Option<Vec<ViewDefinitionOrReference>>,
60    /// Time this data model was created, in milliseconds since epoch.
61    pub created_time: i64,
62    /// Time this data model was last updated, in milliseconds since epoch.
63    pub last_updated_time: i64,
64    /// Whether this data model is global (defined by CDF) or project specific.
65    pub is_global: bool,
66}
67
68#[skip_serializing_none]
69#[derive(Serialize, Deserialize, Clone, Debug, Default)]
70#[serde(rename_all = "camelCase")]
71/// ID of a data model
72pub struct DataModelId {
73    /// Data model space.
74    pub space: String,
75    /// Data model external ID.
76    pub external_id: String,
77    /// Data model version. This is required for some endpoints, but not all.
78    pub version: Option<String>,
79}
80
81#[derive(Clone, Debug, Default)]
82/// Query for listing data models.
83pub struct DataModelQuery {
84    /// Optional cursor for pagination.
85    pub cursor: Option<String>,
86    /// Maximum number of data models to retrieve. Default is 10, maximum is 1000.
87    pub limit: Option<i32>,
88    /// Whether to expand the referenced views inline in the returned result.
89    pub inline_views: Option<bool>,
90    /// Filter by data model space.
91    pub space: Option<String>,
92    /// Whether to include all versions, or just the latest version.
93    pub all_versions: Option<bool>,
94    /// Whether to include global data models.
95    pub include_global: Option<bool>,
96}
97
98impl SetCursor for DataModelQuery {
99    fn set_cursor(&mut self, cursor: Option<String>) {
100        self.cursor = cursor;
101    }
102}
103
104impl IntoParams for DataModelQuery {
105    fn into_params(self) -> Vec<(String, String)> {
106        let mut params = Vec::new();
107        to_query("cursor", &self.cursor, &mut params);
108        to_query("limit", &self.limit, &mut params);
109        to_query("inlineViews", &self.inline_views, &mut params);
110        to_query("space", &self.space, &mut params);
111        to_query("allVersions", &self.all_versions, &mut params);
112        to_query("includeGlobal", &self.include_global, &mut params);
113        params
114    }
115}