Skip to content

Commit 05d9b06

Browse files
authored
Merge pull request #38 from ucwong/dev
add bolt batch func
2 parents 624bee3 + dbb8c12 commit 05d9b06

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

bolt/bolt.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,13 @@ func (b *Bolt) Close() error {
213213
}
214214

215215
func (b *Bolt) Batch(kvs map[string][]byte) error {
216-
panic("Not support")
216+
return b.engine.Batch(func(tx *bolt.Tx) error {
217+
bucket := tx.Bucket([]byte(GLOBAL))
218+
for k, v := range kvs {
219+
if err := bucket.Put([]byte(k), v); err != nil {
220+
return err
221+
}
222+
}
223+
return nil
224+
})
217225
}

bolt/bolt_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ func bolt1() {
7171
for _, i := range res {
7272
fmt.Printf("suffix...%v...%s\n", len(res), string(i))
7373
}
74+
kvs := make(map[string][]byte)
75+
kvs["batch1"] = []byte("batchv1")
76+
kvs["batch2"] = []byte("batchv2")
77+
kvs["batch3"] = []byte("batchv3")
78+
kvs["batch4"] = []byte("batchv4")
79+
db.Batch(kvs)
80+
res = db.Prefix([]byte("batch"))
81+
for _, i := range res {
82+
fmt.Printf("prefix(batch)...%v...%s\n", len(res), string(i))
83+
}
7484
res = db.Scan()
7585
for _, i := range res {
7686
fmt.Printf("scan...%v...%v\n", len(res), len(i))

0 commit comments

Comments
 (0)