Documentation
¶
Index ¶
- Variables
- func FindNodes(node *node, lower []byte, upper []byte, fn func(*node))
- func IsValidDatabase(path string) error
- func Remove(path string) error
- type Database
- type LookupIterator
- type Transaction
- func (tx *Transaction) Commit() error
- func (tx *Transaction) CommitSync() error
- func (tx *Transaction) Get(key []byte) (value []byte, err error)
- func (tx *Transaction) GetID() uint64
- func (tx *Transaction) Lookup(lower []byte, upper []byte) (LookupIterator, error)
- func (tx *Transaction) Put(key []byte, value []byte) error
- func (tx *Transaction) Remove(key []byte) ([]byte, error)
- func (tx *Transaction) Rollback() error
- type Tree
- type TreeEntry
Constants ¶
This section is empty.
Variables ¶
var DatabaseClosed = errors.New("database closed")
var DatabaseHasOpenTransactions = errors.New("database has open transactions")
var DatabaseInUse = errors.New("database in use")
var EmptyKey = errors.New("key is empty")
var EndOfIterator = errors.New("end of iterator")
var KeyNotFound = errors.New("key not found")
var KeyTooLong = errors.New("key too long, max 1024")
var NoDatabaseFound = errors.New("no database found")
var NotADirectory = errors.New("path is not a directory")
var NotValidDatabase = errors.New("path is not a valid database")
var ReadOnlySegment = errors.New("read only segment")
var TransactionClosed = errors.New("transaction closed")
Functions ¶
func IsValidDatabase ¶
IsValidDatabase checks if the path points to a valid database or empty directory (which is also valid)
Types ¶
type Database ¶
Database reference is obtained via Open()
func Open ¶
Open a database. The database can only be opened by a single process, but the *Database reference can be shared across Go routines. The path is a directory name. if createIfNeeded is true, them if the db doesn't exist it will be created Additional tables can be added on subsequent opens, but there is no current way to delete a table, except for deleting the table related files from the directory
func (*Database) BeginTX ¶
func (db *Database) BeginTX(table string) (*Transaction, error)
BeginTX starts a transaction for a database table. a Transaction can only be used by a single Go routine. each transaction should be completed with either Commit, or Rollback
func (*Database) Close ¶
Close the database. any memory segments are persisted to disk. The resulting segments are merged until the default maxSegments is reached
func (*Database) CloseWithMerge ¶
CloseWithMerge closes the database with control of the segment count. if segmentCount is 0, then the merge process is skipped
type LookupIterator ¶
type LookupIterator interface { // returns EndOfIterator when complete, if err is nil, then key and value are valid Next() (key []byte, value []byte, err error) // contains filtered or unexported methods }
LookupIterator iterator interface for table scanning. all iterators should be read until completion
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction for keydb operations
func (*Transaction) Commit ¶
func (tx *Transaction) Commit() error
Commit persists any changes to the table. after Commit the transaction can no longer be used
func (*Transaction) CommitSync ¶
func (tx *Transaction) CommitSync() error
CommitSync persists any changes to the table, waiting for disk segment to be written. note that synchronous writes are not used, so that a hard OS failure could leave the database in a corrupted state. after Commit the transaction can no longer be used
func (*Transaction) Get ¶
func (tx *Transaction) Get(key []byte) (value []byte, err error)
Get a value for a key, error is non-nil if the key was not found or an error occurred
func (*Transaction) GetID ¶
func (tx *Transaction) GetID() uint64
GetID returns the internal transaction identifier
func (*Transaction) Lookup ¶
func (tx *Transaction) Lookup(lower []byte, upper []byte) (LookupIterator, error)
Lookup finds matching record between lower and upper inclusive. lower or upper can be nil and and then the range is unbounded on that side. Using the iterator after the transaction has been Commit/Rollback is not supported.
func (*Transaction) Put ¶
func (tx *Transaction) Put(key []byte, value []byte) error
Put a key/value pair into the table, overwriting any existing entry. empty keys are not supported.
func (*Transaction) Remove ¶
func (tx *Transaction) Remove(key []byte) ([]byte, error)
Remove a key and its value from the table. empty keys are not supported.
func (*Transaction) Rollback ¶
func (tx *Transaction) Rollback() error
Rollback discards any changes to the table. after Rollback the transaction can no longer be used
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is an auto balancing CVL tree, based on code from 'applied go', but modified for []byte key and values, and range searching