@@ -13,7 +13,6 @@ use rusqlite::TransactionBehavior;
13
13
14
14
use aw_models:: Bucket ;
15
15
use aw_models:: Event ;
16
- use aw_models:: KeyValue ;
17
16
18
17
use crate :: DatastoreError ;
19
18
use crate :: DatastoreInstance ;
@@ -51,8 +50,8 @@ pub enum Response {
51
50
Event ( Event ) ,
52
51
EventList ( Vec < Event > ) ,
53
52
Count ( i64 ) ,
54
- KeyValue ( KeyValue ) ,
55
- StringVec ( Vec < String > ) ,
53
+ KeyValue ( String ) ,
54
+ KeyValues ( HashMap < String , String > ) ,
56
55
}
57
56
58
57
#[ allow( clippy:: large_enum_variant) ]
@@ -74,9 +73,9 @@ pub enum Command {
74
73
GetEventCount ( String , Option < DateTime < Utc > > , Option < DateTime < Utc > > ) ,
75
74
DeleteEventsById ( String , Vec < i64 > ) ,
76
75
ForceCommit ( ) ,
77
- InsertKeyValue ( String , String ) ,
76
+ GetKeyValues ( String ) ,
78
77
GetKeyValue ( String ) ,
79
- GetKeysStarting ( String ) ,
78
+ SetKeyValue ( String , String ) ,
80
79
DeleteKeyValue ( String ) ,
81
80
Close ( ) ,
82
81
}
@@ -275,18 +274,18 @@ impl DatastoreWorker {
275
274
self . commit = true ;
276
275
Ok ( Response :: Empty ( ) )
277
276
}
278
- Command :: InsertKeyValue ( key, data) => match ds. insert_key_value ( tx, & key, & data) {
277
+ Command :: GetKeyValues ( pattern) => match ds. get_key_values ( tx, pattern. as_str ( ) ) {
278
+ Ok ( result) => Ok ( Response :: KeyValues ( result) ) ,
279
+ Err ( e) => Err ( e) ,
280
+ } ,
281
+ Command :: SetKeyValue ( key, data) => match ds. insert_key_value ( tx, & key, & data) {
279
282
Ok ( ( ) ) => Ok ( Response :: Empty ( ) ) ,
280
283
Err ( e) => Err ( e) ,
281
284
} ,
282
285
Command :: GetKeyValue ( key) => match ds. get_key_value ( tx, & key) {
283
286
Ok ( result) => Ok ( Response :: KeyValue ( result) ) ,
284
287
Err ( e) => Err ( e) ,
285
288
} ,
286
- Command :: GetKeysStarting ( pattern) => match ds. get_keys_starting ( tx, & pattern) {
287
- Ok ( result) => Ok ( Response :: StringVec ( result) ) ,
288
- Err ( e) => Err ( e) ,
289
- } ,
290
289
Command :: DeleteKeyValue ( key) => match ds. delete_key_value ( tx, & key) {
291
290
Ok ( ( ) ) => Ok ( Response :: Empty ( ) ) ,
292
291
Err ( e) => Err ( e) ,
@@ -475,46 +474,46 @@ impl Datastore {
475
474
}
476
475
}
477
476
478
- pub fn insert_key_value ( & self , key : & str , data : & str ) -> Result < ( ) , DatastoreError > {
479
- let cmd = Command :: InsertKeyValue ( key. to_string ( ) , data. to_string ( ) ) ;
480
- let receiver = self . requester . request ( cmd) . unwrap ( ) ;
481
-
482
- _unwrap_response ( receiver)
483
- }
484
-
485
- pub fn delete_key_value ( & self , key : & str ) -> Result < ( ) , DatastoreError > {
486
- let cmd = Command :: DeleteKeyValue ( key. to_string ( ) ) ;
487
- let receiver = self . requester . request ( cmd) . unwrap ( ) ;
488
-
489
- _unwrap_response ( receiver)
490
- }
491
-
492
- pub fn get_key_value ( & self , key : & str ) -> Result < KeyValue , DatastoreError > {
493
- let cmd = Command :: GetKeyValue ( key. to_string ( ) ) ;
477
+ pub fn get_key_values ( & self , pattern : & str ) -> Result < HashMap < String , String > , DatastoreError > {
478
+ let cmd = Command :: GetKeyValues ( pattern. to_string ( ) ) ;
494
479
let receiver = self . requester . request ( cmd) . unwrap ( ) ;
495
480
496
481
match receiver. collect ( ) . unwrap ( ) {
497
482
Ok ( r) => match r {
498
- Response :: KeyValue ( value) => Ok ( value) ,
483
+ Response :: KeyValues ( value) => Ok ( value) ,
499
484
_ => panic ! ( "Invalid response" ) ,
500
485
} ,
501
486
Err ( e) => Err ( e) ,
502
487
}
503
488
}
504
489
505
- pub fn get_keys_starting ( & self , pattern : & str ) -> Result < Vec < String > , DatastoreError > {
506
- let cmd = Command :: GetKeysStarting ( pattern . to_string ( ) ) ;
490
+ pub fn get_key_value ( & self , key : & str ) -> Result < String , DatastoreError > {
491
+ let cmd = Command :: GetKeyValue ( key . to_string ( ) ) ;
507
492
let receiver = self . requester . request ( cmd) . unwrap ( ) ;
508
493
509
494
match receiver. collect ( ) . unwrap ( ) {
510
495
Ok ( r) => match r {
511
- Response :: StringVec ( value ) => Ok ( value ) ,
496
+ Response :: KeyValue ( kv ) => Ok ( kv ) ,
512
497
_ => panic ! ( "Invalid response" ) ,
513
498
} ,
514
499
Err ( e) => Err ( e) ,
515
500
}
516
501
}
517
502
503
+ pub fn set_key_value ( & self , key : & str , data : & str ) -> Result < ( ) , DatastoreError > {
504
+ let cmd = Command :: SetKeyValue ( key. to_string ( ) , data. to_string ( ) ) ;
505
+ let receiver = self . requester . request ( cmd) . unwrap ( ) ;
506
+
507
+ _unwrap_response ( receiver)
508
+ }
509
+
510
+ pub fn delete_key_value ( & self , key : & str ) -> Result < ( ) , DatastoreError > {
511
+ let cmd = Command :: DeleteKeyValue ( key. to_string ( ) ) ;
512
+ let receiver = self . requester . request ( cmd) . unwrap ( ) ;
513
+
514
+ _unwrap_response ( receiver)
515
+ }
516
+
518
517
// Should block until worker has stopped
519
518
pub fn close ( & self ) {
520
519
info ! ( "Sending close request to database" ) ;
0 commit comments