mirror of https://github.com/poanetwork/quorum.git
c215989c10
Co-authored-by: amalraj.manigmail.com <amalraj.manigmail.com> Co-authored-by: Péter Szilágyi <peterke@gmail.com> Co-authored-by: Flash Sheridan <flash@pobox.com> Co-authored-by: Martin Holst Swende <martin@swende.se> Co-authored-by: Nguyen Kien Trung <trung.n.k@gmail.com> Co-authored-by: Felix Lange <fjl@twurst.com> Co-authored-by: Rob Mulholand <rmulholand@8thlight.com> Co-authored-by: Felföldi Zsolt <zsfelfoldi@gmail.com> Co-authored-by: soc1c <soc1c@users.noreply.github.com> Co-authored-by: Rafael Matias <rafael@skyle.net> Co-authored-by: gary rong <garyrong0905@gmail.com> Co-authored-by: Lucas Hendren <lhendre2@gmail.com> Co-authored-by: Ryan Schneider <ryanleeschneider@gmail.com> Co-authored-by: ywzqwwt <39263032+ywzqwwt@users.noreply.github.com> Co-authored-by: zcheng9 <zcheng9@hawk.iit.edu> Co-authored-by: zzy96 <zhou0250@e.ntu.edu.sg> Co-authored-by: kikilass <36239971+kikilass@users.noreply.github.com> Co-authored-by: Darrel Herbst <dherbst@gmail.com> Co-authored-by: Ross <9055337+Chadsr@users.noreply.github.com> Co-authored-by: Jeffery Robert Walsh <rlxrlps@gmail.com> Co-authored-by: Marius Kjærstad <sandakersmann@users.noreply.github.com> Co-authored-by: Piotr Dyraga <piotr.dyraga@keep.network> Co-authored-by: Guillaume Ballet <gballet@gmail.com> Co-authored-by: Michael Forney <mforney@mforney.org> Co-authored-by: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> |
||
---|---|---|
.. | ||
leveldb | ||
LICENSE | ||
README.md |
README.md
This is an implementation of the LevelDB key/value database in the Go programming language.
Installation
go get github.com/syndtr/goleveldb/leveldb
Requirements
- Need at least
go1.5
or newer.
Usage
Create or open a database:
// The returned DB instance is safe for concurrent use. Which mean that all
// DB's methods may be called concurrently from multiple goroutine.
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.