From http://code.google.com/p/leveldb/, it seems not explicit or easy to use LevelDB with Go. But I really want to know how to use it in Go.
Could anyone give me a clue?
This is useful if you have data that you want to store that you don't want to encode into a string. LevelDB supports atomic operations. You can run many operations at once in a single uninterruptible call.
LevelDB is an on-disk key-value store where the keys and values are both arbitrary blobs of data. Each LevelDB database occupies a folder on the file system. The folder will contain some combination of files named “CURRENT”, “LOCK”, “LOG”, “LOG. old” and files named “MANIFEST-######”, “######.
Features. LevelDB stores keys and values in arbitrary byte arrays, and data is sorted by key. It supports batching writes, forward and backward iteration, and compression of the data via Google's Snappy compression library. LevelDB is not an SQL database.
Here is a Go implementation of LevelDB https://github.com/syndtr/goleveldb
Here is how to use it:
go get github.com/syndtr/goleveldb/leveldb
Create or open database:
db, err := leveldb.OpenFile("path/to/db", nil)
...
defer db.Close()
...
Read or modify the database content:
data, err := db.Get([]byte("key"), nil)
...
err = db.Put([]byte("key"), []byte("value"), nil)
...
err = db.Delete([]byte("key"), nil)
...
Use levigo - a Golang wrapper around the C++ version of LevelDB.
The file levigo/leveldb_test.go gives you an example of how to use levigo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With