1
1
use alloc:: format;
2
2
use alloc:: string:: String ;
3
3
4
+ use crate :: bucket_priority:: BucketPriority ;
4
5
use crate :: error:: { PSResult , SQLiteError } ;
5
6
use sqlite_nostd as sqlite;
6
7
use sqlite_nostd:: { Connection , ResultCode } ;
@@ -17,8 +18,11 @@ SELECT
17
18
json_extract(e.value, '$.data') as data,
18
19
json_extract(e.value, '$.has_more') as has_more,
19
20
json_extract(e.value, '$.after') as after,
20
- json_extract(e.value, '$.next_after') as next_after
21
- FROM json_each(json_extract(?, '$.buckets')) e" ,
21
+ json_extract(e.value, '$.next_after') as next_after,
22
+ json_extract(d.value, '$.priority') as priority,
23
+ FROM json_each(json_extract(?1, '$.buckets')) e
24
+ LEFT OUTER JOIN json_each(json_extract(?1, '$.descriptions')) d
25
+ ON json_extract(e.value, '$.bucket') == d.key" ,
22
26
) ?;
23
27
statement. bind_text ( 1 , data, sqlite:: Destructor :: STATIC ) ?;
24
28
@@ -28,8 +32,15 @@ FROM json_each(json_extract(?, '$.buckets')) e",
28
32
// let _has_more = statement.column_int(2)? != 0;
29
33
// let _after = statement.column_text(3)?;
30
34
// let _next_after = statement.column_text(4)?;
35
+ let priority = match statement. column_type ( 5 ) ? {
36
+ sqlite_nostd:: ColumnType :: Integer => {
37
+ BucketPriority :: try_from ( statement. column_int ( 5 ) ?) . ok ( )
38
+ }
39
+ _ => None ,
40
+ }
41
+ . unwrap_or_default ( ) ;
31
42
32
- insert_bucket_operations ( db, bucket, data) ?;
43
+ insert_bucket_operations ( db, bucket, data, priority ) ?;
33
44
}
34
45
35
46
Ok ( ( ) )
@@ -39,6 +50,7 @@ pub fn insert_bucket_operations(
39
50
db : * mut sqlite:: sqlite3 ,
40
51
bucket : & str ,
41
52
data : & str ,
53
+ priority : BucketPriority ,
42
54
) -> Result < ( ) , SQLiteError > {
43
55
// Statement to insert new operations (only for PUT and REMOVE).
44
56
// language=SQLite
@@ -60,13 +72,14 @@ FROM json_each(?) e",
60
72
// We can consider splitting this into separate SELECT and INSERT statements.
61
73
// language=SQLite
62
74
let bucket_statement = db. prepare_v2 (
63
- "INSERT INTO ps_buckets(name)
64
- VALUES(?)
75
+ "INSERT INTO ps_buckets(name, priority )
76
+ VALUES(?, ? )
65
77
ON CONFLICT DO UPDATE
66
78
SET last_applied_op = last_applied_op
67
79
RETURNING id, last_applied_op" ,
68
80
) ?;
69
81
bucket_statement. bind_text ( 1 , bucket, sqlite:: Destructor :: STATIC ) ?;
82
+ bucket_statement. bind_int ( 2 , priority. into ( ) ) ;
70
83
bucket_statement. step ( ) ?;
71
84
72
85
let bucket_id = bucket_statement. column_int64 ( 0 ) ?;
0 commit comments