Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when a key doesn't exist. ErrNotFound = errors.New("key does not exist") // ErrInvalidBatch is returned when a batch is invalid. ErrInvalidBatch = errors.New("batch is invalid") // ErrInvalidTransaction is returned when a transaction is invalid. ErrInvalidTransaction = errors.New("transaction is invalid") )
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch interface { // Put sets or overwrites the value of a key. Put(key, value []byte) // Delete removes a key. Delete(key []byte) }
Batch can execute multiple write operations efficiently. It is only intended to be used once. When writing the batch to the database, the operations may execute concurrently, so order is not guaranteed.
type Batcher ¶
type Batcher interface { // Batch creates a batch which can be used to execute multiple write // operations atomically and efficiently. Batch() Batch // Write executes all the operations in a batch atomically. It may // write concurrently. Write(Batch) error }
Batcher can batch write.
type DB ¶
type DB interface { Reader Ranger Writer Batcher Transactor // Close may close the underlying storage. Close() error }
DB can read and write values to a key-value database.
Implementations should be concurrently safe.
func NewFileDB ¶
NewFileDB creates a new LevelDB key-value database from a LevelDB file.
Options can be nil. LevelDB has some interesting options to look at to improve performance, such as BloomFilter.
func NewLevelDB ¶
NewLevelDB creates a new LevelDB key-value database from an existing LevelDB database instance.
type Diff ¶
type Diff struct {
// contains filtered or unexported fields
}
Diff implements ReadWriter and records changes that need to be applied to an underlying database. The recorded changes can then be applied atomically using a batch. It ensures only one write operation per key changed.
func NewDiff ¶
func NewDiff(db ReadWriteBatcher) *Diff
NewDiff creates a new Diff with the given underlying database.
func (*Diff) Apply ¶
Apply applies all the recorded changes to the underlying database. It also resets the recorded changes.
type Iterator ¶
type Iterator interface { // Next returns whether there are keys left. Next() (bool, error) // Key returns the key of the current entry. Key() []byte // Value returns the value of the current entry. Value() []byte // Release needs to be called to free the iterator. Release() }
Iterator iterates over a range of keys in the key-value database.
type Ranger ¶
type Ranger interface { // IterateRange creates an iterator that iterates from the given start // key (inclusive) up to the given stop key (exclusive). Remember to // call Release() on the iterator. IterateRange(start, stop []byte) Iterator // IteratePrefix creates an iterator that iterates over all the keys // that begin with the given prefix. Remember to call Release() on the // iterator. IteratePrefix(prefix []byte) Iterator }
Ranger can iterate over ranges.
type ReadWriteBatcher ¶
type ReadWriteBatcher interface { ReadWriter Batcher }
ReadWriteBatcher can both read, write, and batch write values to a key-value database.
type ReadWriter ¶
ReadWriter can both read and write values to a key-value database.
type Reader ¶
type Reader interface { // Get returns the value of a key. If the key doesn't exist, it returns // ErrNotFound (which feels a bit safer than returning nil). Get(key []byte) ([]byte, error) }
Reader reads values from a key-value database.
type Transaction ¶
type Transaction interface { Reader Ranger Writer Batcher // Commit should be called to commit the transaction to the database. Commit() error // Discard should be called to discard the transaction. Discard() }
Transaction can be used to execute multiple operations atomically. It should be closed exactly once by calling either Commit or Discard.
type Transactor ¶
type Transactor interface { // Transaction creates a transaction which can be used to execute // multiple operations atomically. Transaction() (Transaction, error) }
Transactor can create database transactions.