@@ -12,22 +12,22 @@ import (
12
12
)
13
13
14
14
var (
15
- _ kvql.Txn = (* queryTxn )(nil )
16
- _ kvql.Cursor = (* queryCursor )(nil )
15
+ _ kvql.Storage = (* queryStorage )(nil )
16
+ _ kvql.Cursor = (* queryCursor )(nil )
17
17
)
18
18
19
- type queryTxn struct {
19
+ type queryStorage struct {
20
20
client client.Client
21
21
}
22
22
23
- func NewQueryTxn (client client.Client ) kvql.Txn {
24
- return & queryTxn {
23
+ func NewQueryStorage (client client.Client ) kvql.Storage {
24
+ return & queryStorage {
25
25
client : client ,
26
26
}
27
27
}
28
28
29
- func (t * queryTxn ) Get (key []byte ) ([]byte , error ) {
30
- kv , err := t .client .Get (context .TODO (), client .Key (key ))
29
+ func (s * queryStorage ) Get (key []byte ) ([]byte , error ) {
30
+ kv , err := s .client .Get (context .TODO (), client .Key (key ))
31
31
if err != nil {
32
32
if err .Error () == "not exist" {
33
33
return nil , nil
@@ -37,41 +37,41 @@ func (t *queryTxn) Get(key []byte) ([]byte, error) {
37
37
return kv .V , nil
38
38
}
39
39
40
- func (t * queryTxn ) Put (key []byte , value []byte ) error {
41
- return t .client .Put (context .TODO (), client.KV {K : key , V : value })
40
+ func (s * queryStorage ) Put (key []byte , value []byte ) error {
41
+ return s .client .Put (context .TODO (), client.KV {K : key , V : value })
42
42
}
43
43
44
- func (t * queryTxn ) BatchPut (kvs []kvql.KVPair ) error {
45
- var kvs2 []client.KV
46
- for _ , kv := range kvs {
47
- kvs2 = append ( kvs2 , client.KV {K : kv .Key , V : kv .Value })
44
+ func (s * queryStorage ) BatchPut (kvs []kvql.KVPair ) error {
45
+ tkvs := make ( []client.KV , len ( kvs ))
46
+ for i , kv := range kvs {
47
+ tkvs [ i ] = client.KV {K : kv .Key , V : kv .Value }
48
48
}
49
- return t .client .BatchPut (context .TODO (), kvs2 )
49
+ return s .client .BatchPut (context .TODO (), tkvs )
50
50
}
51
51
52
- func (t * queryTxn ) Delete (key []byte ) error {
53
- return t .client .Delete (context .TODO (), key )
52
+ func (s * queryStorage ) Delete (key []byte ) error {
53
+ return s .client .Delete (context .TODO (), key )
54
54
}
55
55
56
- func (t * queryTxn ) BatchDelete (keys [][]byte ) error {
57
- var kvs []client.KV
58
- for _ , k := range keys {
59
- kvs = append ( kvs , client.KV {K : k })
56
+ func (s * queryStorage ) BatchDelete (keys [][]byte ) error {
57
+ tkvs := make ( []client.KV , len ( keys ))
58
+ for i , key := range keys {
59
+ tkvs [ i ] = client.KV {K : key }
60
60
}
61
- return t .client .BatchDelete (context .TODO (), kvs )
61
+ return s .client .BatchDelete (context .TODO (), tkvs )
62
62
}
63
63
64
- func (t * queryTxn ) Cursor () (kvql.Cursor , error ) {
64
+ func (s * queryStorage ) Cursor () (kvql.Cursor , error ) {
65
65
return & queryCursor {
66
- txn : t ,
66
+ storage : s ,
67
67
batch : nil ,
68
68
prefix : []byte {},
69
69
iterPos : 0 ,
70
70
}, nil
71
71
}
72
72
73
73
type queryCursor struct {
74
- txn * queryTxn
74
+ storage * queryStorage
75
75
batch client.KVS
76
76
batchSize int
77
77
prefix []byte
@@ -86,7 +86,7 @@ func (c *queryCursor) loadBatch() error {
86
86
scanOpt .Set (tcli .ScanOptCountOnly , "false" )
87
87
scanOpt .Set (tcli .ScanOptStrictPrefix , "false" )
88
88
qctx := utils .ContextWithProp (context .TODO (), scanOpt )
89
- kvs , n , err := c .txn .client .Scan (qctx , c .prefix )
89
+ kvs , n , err := c .storage .client .Scan (qctx , c .prefix )
90
90
if err != nil {
91
91
return err
92
92
}
0 commit comments