# README
This is an implementation of the LevelDB key/value database in the Go programming language.
Installation
go get github.com/3JoB/goleveldb
Requirements
- Need at least
go1.20
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.
# Packages
Package cache provides interface and implementation of a cache algorithms.
Package comparer provides interface and implementation for ordering sets of data.
Package errors provides common error types used throughout leveldb.
Package filter provides interface and implementation of probabilistic data structure.
Package iterator provides interface and implementation to traverse over contents of a database.
Package journal reads and writes sequences of journals.
No description provided by the author
Package memdb provides in-memory key/value database implementation.
Package opt provides sets of options used by LevelDB.
Package storage provides storage abstraction for LevelDB.
Package table allows read and write sorted key/value.
No description provided by the author
Package util provides utilities used throughout leveldb.
# Functions
MakeBatch returns empty batch with preallocated buffer.
MakeBatchWithConfig initializes a batch object with the given configs.
Open opens or creates a DB for the given storage.
OpenFile opens or creates a DB for the given path.
Recover recovers and opens a DB with missing or corrupted manifest files for the given storage.
RecoverFile recovers and opens a DB with missing or corrupted manifest files for the given path.
# Variables
Common errors.
Common errors.
Common errors.
Common errors.
Common errors.
# Structs
Batch is a write batch.
BatchConfig contains the config options for batch.
DB is a LevelDB database.
DBStats is database statistics.
ErrBatchCorrupted records reason of batch corruption.
ErrInternalKeyCorrupted records internal key corruption.
ErrManifestCorrupted records manifest corruption.
Snapshot is a DB snapshot.
Transaction is the transaction handle.
# Interfaces
BatchReplay wraps basic batch operations.
Reader is the interface that wraps basic Get and NewIterator methods.
# Type aliases
Sizes is list of size.