orientdb_client/common/protocol/messages/
request.rs1use crate::common::types::value::OValue;
2use crate::common::DatabaseType;
3use std::collections::HashMap;
4
5#[derive(Debug)]
6pub struct HandShake {
7 pub p_version: i16,
8 pub name: String,
9 pub version: String,
10}
11
12impl HandShake {
13 pub fn new<T>(p_version: i16, name: T, version: T) -> HandShake
14 where
15 T: Into<String>,
16 {
17 HandShake {
18 p_version,
19 name: name.into(),
20 version: version.into(),
21 }
22 }
23}
24
25impl From<HandShake> for Request {
26 fn from(input: HandShake) -> Request {
27 Request::HandShake(input)
28 }
29}
30
31#[derive(Debug)]
32pub struct MsgHeader {
33 pub session_id: i32,
34 pub token: Option<Vec<u8>>,
35}
36
37impl MsgHeader {
38 pub fn new(session_id: i32, token: Option<Vec<u8>>) -> MsgHeader {
39 MsgHeader { session_id, token }
40 }
41}
42#[derive(Debug)]
44pub struct Connect {
45 pub username: String,
46 pub password: String,
47}
48
49impl Connect {
50 pub fn new<T>(username: T, password: T) -> Connect
51 where
52 T: Into<String>,
53 {
54 Connect {
55 username: username.into(),
56 password: password.into(),
57 }
58 }
59}
60
61impl From<Connect> for Request {
62 fn from(input: Connect) -> Request {
63 Request::Connect(input)
64 }
65}
66
67#[derive(Debug)]
69pub struct Open {
70 pub db: String,
71 pub username: String,
72 pub password: String,
73}
74
75impl Open {
76 pub fn new<T>(db: T, username: T, password: T) -> Open
77 where
78 T: Into<String>,
79 {
80 Open {
81 db: db.into(),
82 username: username.into(),
83 password: password.into(),
84 }
85 }
86}
87
88impl From<Open> for Request {
89 fn from(input: Open) -> Request {
90 Request::Open(input)
91 }
92}
93
94#[derive(Debug)]
95pub struct LiveQuery {
96 pub session_id: i32,
97 pub token: Option<Vec<u8>>,
98 pub query: String,
99 pub parameters: HashMap<String, OValue>,
100 pub named: bool,
101}
102
103impl LiveQuery {
104 pub fn new<T: Into<String>>(
105 session_id: i32,
106 token: Option<Vec<u8>>,
107 query: T,
108 parameters: HashMap<String, OValue>,
109 named: bool,
110 ) -> LiveQuery {
111 LiveQuery {
112 session_id,
113 token,
114 query: query.into(),
115 parameters,
116 named,
117 }
118 }
119}
120
121impl From<LiveQuery> for Request {
122 fn from(input: LiveQuery) -> Request {
123 Request::LiveQuery(input)
124 }
125}
126
127#[derive(Debug)]
128pub struct UnsubscribeLiveQuery {
129 pub session_id: i32,
130 pub token: Option<Vec<u8>>,
131 pub monitor_id: i32,
132}
133
134impl UnsubscribeLiveQuery {
135 pub fn new(session_id: i32, token: Option<Vec<u8>>, monitor_id: i32) -> UnsubscribeLiveQuery {
136 UnsubscribeLiveQuery {
137 session_id,
138 token,
139 monitor_id,
140 }
141 }
142}
143impl From<UnsubscribeLiveQuery> for Request {
144 fn from(input: UnsubscribeLiveQuery) -> Request {
145 Request::UnsubscribeLiveQuery(input)
146 }
147}
148#[derive(Debug)]
150pub struct Query {
151 pub session_id: i32,
152 pub token: Option<Vec<u8>>,
153 pub query: String,
154 pub parameters: HashMap<String, OValue>,
155 pub named: bool,
156 pub language: String,
157 pub mode: i8,
158 pub page_size: i32,
159}
160
161impl Query {
162 #[allow(clippy::too_many_arguments)]
163 pub fn new<T>(
164 session_id: i32,
165 token: Option<Vec<u8>>,
166 query: T,
167 parameters: HashMap<String, OValue>,
168 named: bool,
169 language: T,
170 mode: i8,
171 page_size: i32,
172 ) -> Query
173 where
174 T: Into<String>,
175 {
176 Query {
177 session_id,
178 token,
179 query: query.into(),
180 parameters,
181 named,
182 language: language.into(),
183 mode,
184 page_size,
185 }
186 }
187}
188
189impl From<Query> for Request {
190 fn from(input: Query) -> Request {
191 Request::Query(input)
192 }
193}
194
195#[derive(Debug)]
196pub struct Close {
197 pub session_id: i32,
198 pub token: Option<Vec<u8>>,
199}
200
201impl Close {
202 pub fn new(session_id: i32, token: Option<Vec<u8>>) -> Close {
203 Close { session_id, token }
204 }
205}
206
207impl From<Close> for Request {
208 fn from(input: Close) -> Request {
209 Request::Close(input)
210 }
211}
212
213#[derive(Debug)]
214pub struct QueryNext {
215 pub session_id: i32,
216 pub token: Option<Vec<u8>>,
217 pub query_id: String,
218 pub page_size: i32,
219}
220
221impl QueryNext {
222 pub fn new<T>(session_id: i32, token: Option<Vec<u8>>, query_id: T, page_size: i32) -> QueryNext
223 where
224 T: Into<String>,
225 {
226 QueryNext {
227 session_id,
228 token,
229 query_id: query_id.into(),
230 page_size,
231 }
232 }
233}
234
235impl From<QueryNext> for Request {
236 fn from(input: QueryNext) -> Request {
237 Request::QueryNext(input)
238 }
239}
240
241#[derive(Debug)]
242pub struct QueryClose {
243 pub session_id: i32,
244 pub token: Option<Vec<u8>>,
245 pub query_id: String,
246}
247
248impl QueryClose {
249 pub fn new<T>(session_id: i32, token: Option<Vec<u8>>, query_id: T) -> QueryClose
250 where
251 T: Into<String>,
252 {
253 QueryClose {
254 session_id,
255 token,
256 query_id: query_id.into(),
257 }
258 }
259}
260
261impl From<QueryClose> for Request {
262 fn from(input: QueryClose) -> Request {
263 Request::QueryClose(input)
264 }
265}
266
267#[derive(Debug)]
269pub struct CreateDB {
270 pub header: MsgHeader,
271 pub name: String,
272 pub db_mode: DatabaseType,
273 pub backup: Option<String>,
274}
275
276impl CreateDB {
277 pub fn new<T>(header: MsgHeader, name: T, db_mode: DatabaseType) -> CreateDB
278 where
279 T: Into<String>,
280 {
281 CreateDB {
282 header,
283 name: name.into(),
284 db_mode,
285 backup: None,
286 }
287 }
288}
289
290impl From<CreateDB> for Request {
291 fn from(input: CreateDB) -> Request {
292 Request::CreateDB(input)
293 }
294}
295
296#[derive(Debug)]
298pub struct ExistDB {
299 pub header: MsgHeader,
300 pub name: String,
301 pub db_mode: DatabaseType,
302}
303
304impl ExistDB {
305 pub fn new<T>(header: MsgHeader, name: T, db_mode: DatabaseType) -> ExistDB
306 where
307 T: Into<String>,
308 {
309 ExistDB {
310 header,
311 name: name.into(),
312 db_mode,
313 }
314 }
315}
316
317impl From<ExistDB> for Request {
318 fn from(input: ExistDB) -> Request {
319 Request::ExistDB(input)
320 }
321}
322
323#[derive(Debug)]
325pub struct DropDB {
326 pub header: MsgHeader,
327 pub name: String,
328 pub db_mode: DatabaseType,
329}
330
331impl DropDB {
332 pub fn new<T>(header: MsgHeader, name: T, db_mode: DatabaseType) -> DropDB
333 where
334 T: Into<String>,
335 {
336 DropDB {
337 header,
338 name: name.into(),
339 db_mode,
340 }
341 }
342}
343
344impl From<DropDB> for Request {
345 fn from(input: DropDB) -> Request {
346 Request::DropDB(input)
347 }
348}
349
350#[derive(Debug)]
351pub enum Request {
352 HandShake(HandShake),
353 Connect(Connect),
354 CreateDB(CreateDB),
355 ExistDB(ExistDB),
356 DropDB(DropDB),
357 Open(Open),
358 Query(Query),
359 LiveQuery(LiveQuery),
360 UnsubscribeLiveQuery(UnsubscribeLiveQuery),
361 QueryNext(QueryNext),
362 QueryClose(QueryClose),
363 Close(Close),
364}
365
366impl Request {
367 pub fn need_response(&self) -> bool {
368 match self {
369 Request::Close(_) => false,
370 _ => true,
371 }
372 }
373}