cognite/api/core/
sequences.rs

1use serde::Serialize;
2
3use crate::api::resource::*;
4use crate::dto::core::sequences::*;
5use crate::error::Result;
6use crate::{IdentityList, Items, LimitCursorPartitionQuery, Patch};
7
8/// A sequence stores a table with up to 400 columns indexed by row number. There can be at most
9/// 400 numeric columns and 200 string columns. Each of the columns has a pre-defined type:
10/// a string, integer, or floating point number.
11pub type SequencesResource = Resource<Sequence>;
12
13impl WithBasePath for SequencesResource {
14    const BASE_PATH: &'static str = "sequences";
15}
16
17impl List<LimitCursorPartitionQuery, Sequence> for SequencesResource {}
18impl Create<AddSequence, Sequence> for SequencesResource {}
19impl SearchItems<'_, SequenceFilter, SequenceSearch, Sequence> for SequencesResource {}
20impl Update<Patch<PatchSequence>, Sequence> for SequencesResource {}
21impl<R> DeleteWithIgnoreUnknownIds<IdentityList<R>> for SequencesResource
22where
23    IdentityList<R>: Serialize,
24    R: Send + Sync,
25{
26}
27impl<R> RetrieveWithIgnoreUnknownIds<IdentityList<R>, Sequence> for SequencesResource
28where
29    IdentityList<R>: Serialize,
30    R: Send + Sync,
31{
32}
33impl FilterWithRequest<SequenceFilterRequest, Sequence> for SequencesResource {}
34
35impl SequencesResource {
36    /// Insert a list of rows into a set of sequences.
37    ///
38    /// # Arguments
39    ///
40    /// * `rows` - Sequence row batches to insert.
41    pub async fn insert_rows(&self, rows: &[InsertSequenceRows]) -> Result<()> {
42        let items = Items::new(rows);
43        self.api_client
44            .post::<::serde_json::Value, _>(&format!("{}/{}", Self::BASE_PATH, "data"), &items)
45            .await?;
46        Ok(())
47    }
48
49    /// Retrieve a rows from a set of sequences.
50    ///
51    /// # Arguments
52    ///
53    /// * `query` - Sequence rows retrieval query.
54    pub async fn retrieve_rows(
55        &self,
56        query: RetrieveSequenceRows,
57    ) -> Result<RetrieveSequenceRowsResponse> {
58        self.api_client
59            .post(&format!("{}/{}", Self::BASE_PATH, "data/list"), &query)
60            .await
61    }
62
63    /// Retrieve the last row from a sequence. The last row is the one with the highest row number,
64    /// not necessarily the one that was ingested the most recently.
65    ///
66    /// # Arguments
67    ///
68    /// * `query` - Sequence row retrieval query.
69    pub async fn retrieve_last_row(
70        &self,
71        query: RetrieveLastSequenceRow,
72    ) -> Result<RetrieveSequenceRowsResponse> {
73        self.api_client
74            .post(&format!("{}/{}", Self::BASE_PATH, "data/latest"), &query)
75            .await
76    }
77
78    /// Delete rows from a set of sequences.
79    ///
80    /// # Arguments
81    ///
82    /// * `query` - Row ranges to delete.
83    pub async fn delete_rows(&self, query: &[DeleteSequenceRows]) -> Result<()> {
84        let items = Items::new(query);
85        self.api_client
86            .post(&format!("{}/{}", Self::BASE_PATH, "data/delete"), &items)
87            .await
88    }
89}