forked from jmhodges/levigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
48 lines (39 loc) · 1.48 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
Package levigo provides the ability to create and access LevelDB databases.
levigo.Open() opens and creates databases.
opts := levigo.NewOptions()
opts.SetCache(levigo.NewLRUCache(3<<30))
opts.SetCreateIfMissing(true)
db, err := levigo.Open("/path/to/db", opts)
*DB.Get(), .Put() and .Delete(), respectively, get the data related to a
single key, put data for a single key into the database, and deletes data for
a single key. Don't worry about copying the byte slices in the arguments and
return values of these methods; LevelDB will copy them for you.
ro := levigo.NewReadOptions()
wo := levigo.NewWriteOptions()
// if ro and wo are not used again, be sure to Close them.
data, err := db.Get(ro, []byte("key"))
...
err = db.Put(wo, []byte("anotherkey"), data)
...
err = db.Delete(wo, []byte("key"))
For bulk reads, use an Iterator. For ones that you do not want to disturb
your live traffic, be sure to call SetFillCache(false) on the ReadOptions you
use when creating the Iterator.
ro := levigo.NewReadOptions()
ro.SetFillCache(false)
it := db.NewIterator(ro)
defer it.Close()
for it = it; it.Valid(); it.Next() {
munge(it.Key(), it.Value())
}
Batching and atomically making writes can be performed with a WriteBatch and
*DB.Write().
wb := levigo.NewWriteBatch()
// defer wb.Close() or use wb.Clear() and reuse.
wb.Delete([]byte("removed"))
wb.Put([]byte("added"), []byte("data"))
wb.Put([]byte("anotheradded"), []byte("more"))
err := db.Write(wo, wb)
*/
package levigo