Documentation ¶
Overview ¶
Package leveldb provides implementation of LevelDB key/value database.
Create or open a database:
db, err := leveldb.OpenFile("path/to/db", &opt.Options{Flag: opt.OFCreateIfMissing}) ...
Read or modify the database content:
ro := &opt.ReadOptions{} wo := &opt.WriteOptions{} data, err := db.Get([]byte("key"), ro) ... err = db.Put([]byte("key"), []byte("value"), wo) ... err = db.Delete([]byte("key"), wo) ...
Iterate over database content:
iter := db.NewIterator(ro) for iter.Next() { key := iter.Key() value := iter.Value() ... } 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, wo) ...
Use bloom filter:
o := &opt.Options{ Flag: opt.OFCreateIfMissing, Filter: filter.NewBloomFilter(10), } db, err := leveldb.Open(stor, o) ...
Index ¶
- type Batch
- type DB
- func (d *DB) Close() error
- func (d *DB) CompactRange(r Range) error
- func (d *DB) Delete(key []byte, wo *opt.WriteOptions) error
- func (d *DB) Get(key []byte, ro *opt.ReadOptions) (value []byte, err error)
- func (d *DB) GetApproximateSizes(rr []Range) (sizes Sizes, err error)
- func (d *DB) GetOptionsSetter() opt.OptionsSetter
- func (d *DB) GetProperty(prop string) (value string, err error)
- func (d *DB) GetSnapshot() (snap *Snapshot, err error)
- func (d *DB) NewIterator(ro *opt.ReadOptions) iterator.Iterator
- func (d *DB) Put(key, value []byte, wo *opt.WriteOptions) error
- func (d *DB) Write(b *Batch, wo *opt.WriteOptions) (err error)
- type Range
- type Reader
- type Sizes
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch struct {
// contains filtered or unexported fields
}
Batch represent a write batch.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represent a database session.
func OpenFile ¶
OpenFile open or create database from given file.
This is alias of:
stor, err := storage.OpenFile("path/to/db") ... db, err := Open(stor, &opt.Options{}) ...
func Recover ¶
Recover recover database with missing or corrupted manifest file. It will ignore any manifest files, valid or not.
func (*DB) CompactRange ¶
CompactRange compact the underlying storage for the key range.
In particular, deleted and overwritten versions are discarded, and the data is rearranged to reduce the cost of operations needed to access the data. This operation should typically only be invoked by users who understand the underlying implementation.
Range.Start==nil is treated as a key before all keys in the database. Range.Limit==nil is treated as a key after all keys in the database. Therefore calling with Start==nil and Limit==nil will compact entire database.
func (*DB) Delete ¶
func (d *DB) Delete(key []byte, wo *opt.WriteOptions) error
Delete remove the database entry (if any) for "key". It is not an error if "key" did not exist in the database.
func (*DB) GetApproximateSizes ¶
GetApproximateSizes calculate approximate sizes of given ranges.
Note that the returned sizes measure file system space usage, so if the user data compresses by a factor of ten, the returned sizes will be one-tenth the size of the corresponding user data size.
The results may not include the sizes of recently written data.
func (*DB) GetOptionsSetter ¶
func (d *DB) GetOptionsSetter() opt.OptionsSetter
GetOptionsSetter return OptionsSetter for this database. OptionsSetter allows safely set options of an opened database.
func (*DB) GetProperty ¶
GetProperty used to query exported database state.
Valid property names include:
"leveldb.num-files-at-level<N>" - return the number of files at level <N>, where <N> is an ASCII representation of a level number (e.g. "0"). "leveldb.stats" - returns a multi-line string that storribes statistics about the internal operation of the DB. "leveldb.sstables" - returns a multi-line string that storribes all of the sstables that make up the db contents.
func (*DB) GetSnapshot ¶
GetSnapshot return a handle to the current DB state. Iterators created with this handle will all observe a stable snapshot of the current DB state. The caller must call *Snapshot.Release() when the snapshot is no longer needed.
func (*DB) NewIterator ¶
func (d *DB) NewIterator(ro *opt.ReadOptions) iterator.Iterator
NewIterator return an iterator over the contents of the latest snapshot of database. The result of NewIterator() is initially invalid (caller must call Next or one of Seek method, i.e. First, Last or Seek).
Please note that the iterator is not thread-safe, you may not use same iterator instance concurrently without external synchronization.
type Range ¶
type Range struct { // Start key, include in the range Start []byte // Limit, not include in the range Limit []byte }
Range represent key range.
type Reader ¶
type Reader interface { Get(key []byte, ro *opt.ReadOptions) (value []byte, err error) NewIterator(ro *opt.ReadOptions) iterator.Iterator }
Reader is the interface that wraps basic Get and NewIterator methods. This interface implemented by both *DB and *Snapshot.
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot represent a database snapshot.
func (*Snapshot) NewIterator ¶
func (p *Snapshot) NewIterator(ro *opt.ReadOptions) iterator.Iterator
NewIterator return an iterator over the contents of this snapshot of database.
Please note that the iterator is not thread-safe, you may not use same iterator instance concurrently without external synchronization.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package block allows read and write sorted key/value.
|
Package block allows read and write sorted key/value. |
Package cache provides interface and implementation of a cache algorithms.
|
Package cache provides interface and implementation of a cache algorithms. |
Package comparer provides interface and implementation for ordering sets of data.
|
Package comparer provides interface and implementation for ordering sets of data. |
Package errors implements functions to manipulate errors.
|
Package errors implements functions to manipulate errors. |
Package filter provides interface and implementation of probabilistic data structure.
|
Package filter provides interface and implementation of probabilistic data structure. |
Package hash provides hashing utilities used by leveldb.
|
Package hash provides hashing utilities used by leveldb. |
Package iterator provides interface and implementation to traverse over contents of a database.
|
Package iterator provides interface and implementation to traverse over contents of a database. |
Package journal allows read and write sequence of data block.
|
Package journal allows read and write sequence of data block. |
Package memdb provide in-memory key/value database implementation.
|
Package memdb provide in-memory key/value database implementation. |
Package opt provides sets of options used by LevelDB.
|
Package opt provides sets of options used by LevelDB. |
Package storage provides storage abstraction for LevelDB.
|
Package storage provides storage abstraction for LevelDB. |
Package table allows read and write sorted key/value.
|
Package table allows read and write sorted key/value. |