surrealcs_kernel/messages/server/
kv_operations.rs

1//! The key value operations that can be performed on the key value store.
2use revision::revisioned;
3use serde::{Deserialize, Serialize};
4
5/// Check if a key exists.
6///
7/// # Fields
8/// * `key` - The key to check if it exists.
9#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
10#[revisioned(revision = 1)]
11pub struct MessageExists {
12	pub key: Vec<u8>,
13	pub version: Option<u64>,
14}
15
16/// Get the value of a key.
17///
18/// # Fields
19/// * `key` - The key to get the value of.
20#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
21#[revisioned(revision = 1)]
22pub struct MessageGet {
23	pub key: Vec<u8>,
24	pub version: Option<u64>,
25}
26
27/// Set the value of a key.
28///
29/// # Fields
30/// * `key` - The key to set the value of.
31/// * `value` - The value to set the key to.
32#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
33#[revisioned(revision = 1)]
34pub struct MessageSet {
35	pub key: Vec<u8>,
36	pub value: Vec<u8>,
37	pub version: Option<u64>,
38}
39
40/// Put a key value pair.
41///
42/// # Fields
43/// * `key` - The key to put.
44/// * `value` - The value to put.
45#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
46#[revisioned(revision = 1)]
47pub struct MessagePut {
48	pub key: Vec<u8>,
49	pub value: Vec<u8>,
50	pub version: Option<u64>,
51}
52
53/// Put a key value pair if the value of that key is the same as the one provided.
54///
55/// # Fields
56/// * `key` - The key to put.
57/// * `value` - The value to put.
58/// * `expected_value` - The expected value of the key before the PUT.
59#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
60#[revisioned(revision = 1)]
61pub struct MessagePutc {
62	pub key: Vec<u8>,
63	pub value: Vec<u8>,
64	pub expected_value: Option<Vec<u8>>,
65}
66
67/// Delete a key.
68///
69/// # Fields
70/// * `key` - The key to delete.
71#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
72#[revisioned(revision = 1)]
73pub struct MessageDel {
74	pub key: Vec<u8>,
75}
76
77/// Delete a key if the value of that key is the same as the one provided.
78///
79/// # Fields
80/// * `key` - The key to delete.
81/// * `expected_value` - The expected value of the key before the DELETE.
82#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
83#[revisioned(revision = 1)]
84pub struct MessageDelc {
85	pub key: Vec<u8>,
86	pub expected_value: Option<Vec<u8>>,
87}
88
89/// Delete a key and return the value.
90///
91/// # Fields
92/// * `keys` - The keys to delete.
93#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
94#[revisioned(revision = 1)]
95pub struct MessageDelr {
96	pub begin: Vec<u8>,
97	pub finish: Vec<u8>,
98}
99
100/// Get all keys within a range with a limit.
101///
102/// # Fields
103/// * `begin` - The beginning of the range.
104/// * `finish` - The end of the range.
105/// * `limit` - The limit of the number of keys to return.
106#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
107#[revisioned(revision = 1)]
108pub struct MessageKeys {
109	pub begin: Vec<u8>,
110	pub finish: Vec<u8>,
111	pub limit: u32,
112	pub version: Option<u64>,
113}
114
115/// Get all keys and values within a range with a limit.
116///
117/// # Fields
118/// * `begin` - The beginning of the range.
119/// * `finish` - The end of the range.
120/// * `limit` - The limit of the number of keys to return.
121#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
122#[revisioned(revision = 1)]
123pub struct MessageScan {
124	pub begin: Vec<u8>,
125	pub finish: Vec<u8>,
126	pub limit: u32,
127	pub version: Option<u64>,
128}
129
130/// The response to the `Get` operation.
131///
132/// # Fields
133/// * `value` - The value of the key.
134#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
135#[revisioned(revision = 1)]
136pub struct ResponseGet {
137	pub value: Option<Vec<u8>>,
138}
139
140/// The response to the `Keys` operation.
141///
142/// # Fields
143/// * `keys` - The keys within the range.
144#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
145#[revisioned(revision = 1)]
146pub struct ResponseKeys {
147	pub keys: Vec<Vec<u8>>,
148}
149
150/// The response to the `Scan` operation.
151///
152/// # Fields
153/// * `values` - The key value pairs within the range.
154#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
155#[revisioned(revision = 1)]
156pub struct ResponseScan {
157	pub values: Vec<(Vec<u8>, Vec<u8>)>,
158}