cortex_sdk/client/
core.rs1use super::transport::decode_value;
2use super::CortexDbClient;
3use crate::http::path;
4use crate::{
5 CellLookupResponse, HealthResponse, PutCellResponse, SdkResult, StatsResponse,
6 ValidationResponse, WriteBatchRequest, WriteBatchResponse,
7};
8
9impl CortexDbClient {
10 pub fn health(&self) -> SdkResult<serde_json::Value> {
11 self.get("/v1/health")
12 }
13
14 pub fn health_response(&self) -> SdkResult<HealthResponse> {
15 decode_value(self.health()?)
16 }
17
18 pub fn stats(&self) -> SdkResult<serde_json::Value> {
19 self.get("/v1/stats")
20 }
21
22 pub fn stats_response(&self) -> SdkResult<StatsResponse> {
23 decode_value(self.stats()?)
24 }
25
26 pub fn validate(&self) -> SdkResult<serde_json::Value> {
27 self.get("/v1/validate")
28 }
29
30 pub fn validate_response(&self) -> SdkResult<ValidationResponse> {
31 decode_value(self.validate()?)
32 }
33
34 pub fn put_cell(&self, cell_id: u64, payload: &str) -> SdkResult<serde_json::Value> {
35 self.post(
36 &path("/v1/cell", &[("cell_id", &cell_id.to_string())]),
37 payload,
38 )
39 }
40
41 pub fn put_cell_response(&self, cell_id: u64, payload: &str) -> SdkResult<PutCellResponse> {
42 decode_value(self.put_cell(cell_id, payload)?)
43 }
44
45 pub fn write_batch(&self, request: &WriteBatchRequest) -> SdkResult<serde_json::Value> {
46 let body = serde_json::to_string(request)?;
47 self.post("/v1/batch", &body)
48 }
49
50 pub fn write_batch_response(
51 &self,
52 request: &WriteBatchRequest,
53 ) -> SdkResult<WriteBatchResponse> {
54 decode_value(self.write_batch(request)?)
55 }
56
57 pub fn get_cell(&self, cell_id: u64) -> SdkResult<serde_json::Value> {
58 self.get(&path("/v1/cell", &[("cell_id", &cell_id.to_string())]))
59 }
60
61 pub fn get_cell_response(&self, cell_id: u64) -> SdkResult<CellLookupResponse> {
62 decode_value(self.get_cell(cell_id)?)
63 }
64
65 pub fn tombstone_cell(&self, cell_id: u64) -> SdkResult<serde_json::Value> {
66 self.delete(&path("/v1/cell", &[("cell_id", &cell_id.to_string())]))
67 }
68
69 pub fn flush(&self) -> SdkResult<serde_json::Value> {
70 self.post("/v1/flush", "")
71 }
72
73 pub fn compact(&self) -> SdkResult<serde_json::Value> {
74 self.post("/v1/compact", "")
75 }
76}