ledisdb/vendor/github.com/syndtr/goleveldb
Maciej Lisiewski 2ff56553d9 Dep for dependency management, newer go in CI, dependency updates (#325)
* Use Dep instead of Glide for managing dependencies

* Run tests on the latest two versions of go

* Use older goleveldb

* Don't test vendor (default in go 1.9+)

* Drop Go 1.6 from tests - it's old and I really don't want to deal with it.

* Stop testing with Go 1.7
2017-11-24 09:11:56 +08:00
..
leveldb Dep for dependency management, newer go in CI, dependency updates (#325) 2017-11-24 09:11:56 +08:00
.travis.yml Dep for dependency management, newer go in CI, dependency updates (#325) 2017-11-24 09:11:56 +08:00
LICENSE Dep for dependency management, newer go in CI, dependency updates (#325) 2017-11-24 09:11:56 +08:00
README.md Dep for dependency management, newer go in CI, dependency updates (#325) 2017-11-24 09:11:56 +08:00

README.md

This is an implementation of the LevelDB key/value database in the Go programming language.

Build Status

Installation

go get github.com/syndtr/goleveldb/leveldb

Requirements

  • Need at least go1.4 or newer.

Usage

Create or open a database:

db, err := leveldb.OpenFile("path/to/db", nil)
...
defer db.Close()
...

Read or modify the database content:

// Remember that the contents of the returned slice should not be modified.
data, err := db.Get([]byte("key"), nil)
...
err = db.Put([]byte("key"), []byte("value"), nil)
...
err = db.Delete([]byte("key"), nil)
...

Iterate over database content:

iter := db.NewIterator(nil, nil)
for iter.Next() {
	// Remember that the contents of the returned slice should not be modified, and
	// only valid until the next call to Next.
	key := iter.Key()
	value := iter.Value()
	...
}
iter.Release()
err = iter.Error()
...

Seek-then-Iterate:

iter := db.NewIterator(nil, nil)
for ok := iter.Seek(key); ok; ok = iter.Next() {
	// Use key/value.
	...
}
iter.Release()
err = iter.Error()
...

Iterate over subset of database content:

iter := db.NewIterator(&util.Range{Start: []byte("foo"), Limit: []byte("xoo")}, nil)
for iter.Next() {
	// Use key/value.
	...
}
iter.Release()
err = iter.Error()
...

Iterate over subset of database content with a particular prefix:

iter := db.NewIterator(util.BytesPrefix([]byte("foo-")), nil)
for iter.Next() {
	// Use key/value.
	...
}
iter.Release()
err = iter.Error()
...

Batch writes:

batch := new(leveldb.Batch)
batch.Put([]byte("foo"), []byte("value"))
batch.Put([]byte("bar"), []byte("another value"))
batch.Delete([]byte("baz"))
err = db.Write(batch, nil)
...

Use bloom filter:

o := &opt.Options{
	Filter: filter.NewBloomFilter(10),
}
db, err := leveldb.OpenFile("path/to/db", o)
...
defer db.Close()
...

Documentation

You can read package documentation here.