reql_types/
lib.rs

1//! Common ReQL data types
2
3mod date_time;
4
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7use std::collections::HashMap;
8use std::net::IpAddr;
9use time::OffsetDateTime;
10use uuid::Uuid;
11
12#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
13pub struct DateTime(OffsetDateTime);
14
15impl From<OffsetDateTime> for DateTime {
16    fn from(dt: OffsetDateTime) -> Self {
17        Self(dt)
18    }
19}
20
21impl From<DateTime> for OffsetDateTime {
22    fn from(DateTime(dt): DateTime) -> Self {
23        dt
24    }
25}
26
27/// Status returned by a write command
28#[derive(Debug, Clone, Deserialize, Serialize)]
29#[non_exhaustive]
30pub struct WriteStatus {
31    pub inserted: u32,
32    pub replaced: u32,
33    pub unchanged: u32,
34    pub skipped: u32,
35    pub deleted: u32,
36    pub errors: u32,
37    pub first_error: Option<String>,
38    pub generated_keys: Option<Vec<Uuid>>,
39    pub warnings: Option<Vec<String>>,
40    pub changes: Option<Vec<Change<Value, Value>>>,
41}
42
43/// Structure of data in `cluster_config` table
44#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
45#[non_exhaustive]
46pub struct ClusterConfig {
47    pub id: String,
48    pub heartbeat_timeout_secs: u32,
49}
50
51/// Structure of data in `current_issues` table
52#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
53#[non_exhaustive]
54pub struct CurrentIssue {}
55
56/// Structure of data in `db_config` table
57#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
58#[non_exhaustive]
59pub struct DbConfig {}
60
61/// Structure of data in `jobs` table
62#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
63#[non_exhaustive]
64pub struct Job {}
65
66/// Structure of data in `logs` table
67#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
68#[non_exhaustive]
69pub struct Log {}
70
71/// Structure of data in `permissions` table
72#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
73#[non_exhaustive]
74pub struct Permission {}
75
76/// Structure of data in `server_config` table
77#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
78#[non_exhaustive]
79pub struct ServerConfig {}
80
81#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
82#[non_exhaustive]
83pub struct CanonicalAddress {
84    pub host: IpAddr,
85    pub port: u16,
86}
87
88#[derive(Debug, Clone, Deserialize, Serialize)]
89#[non_exhaustive]
90pub struct Network {
91    pub canonical_addresses: Vec<CanonicalAddress>,
92    pub cluster_port: u16,
93    pub connected_to: HashMap<String, bool>,
94    pub hostname: String,
95    pub http_admin_port: u16,
96    pub reql_port: u16,
97    pub time_connected: DateTime,
98}
99
100#[derive(Debug, Clone, Deserialize, Serialize)]
101#[non_exhaustive]
102pub struct Process {
103    pub argv: Vec<String>,
104    pub cache_size_mb: f64,
105    pub pid: u64,
106    pub time_started: DateTime,
107    pub version: String,
108}
109
110/// Structure of data in `server_status` table
111#[derive(Debug, Clone, Deserialize, Serialize)]
112#[non_exhaustive]
113pub struct ServerStatus {
114    pub id: Uuid,
115    pub name: String,
116    pub network: Network,
117    pub process: Process,
118}
119
120/// Structure of data in `cluster_config` table
121#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
122#[non_exhaustive]
123pub struct Stat {}
124
125/// Structure of data in `cluster_config` table
126#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
127#[non_exhaustive]
128pub struct TableConfig {}
129
130/// Structure of data in `table_status` table
131#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
132#[non_exhaustive]
133pub struct TableStatus {}
134
135/// Structure of data in `uses` table
136#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
137#[non_exhaustive]
138pub struct User {}
139
140#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
141#[non_exhaustive]
142pub struct Change<O, N> {
143    pub old_val: Option<O>,
144    pub new_val: Option<N>,
145    #[serde(rename = "type")]
146    pub result_type: Option<String>,
147    pub old_offset: Option<usize>,
148    pub new_offset: Option<usize>,
149    pub state: Option<String>,
150}
151
152#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
153#[non_exhaustive]
154pub struct ServerInfo {
155    pub id: Uuid,
156    pub proxy: bool,
157    pub name: Option<String>,
158}
159
160#[derive(Debug, Serialize, Deserialize)]
161#[allow(clippy::upper_case_acronyms)]
162struct BINARY;
163
164#[derive(Debug, Serialize, Deserialize)]
165pub struct Binary {
166    #[serde(rename = "$reql_type$")]
167    reql_type: BINARY,
168    pub data: String,
169}
170
171impl Binary {
172    pub fn new(bytes: &[u8]) -> Self {
173        Self {
174            reql_type: BINARY,
175            data: base64::encode(bytes),
176        }
177    }
178}