ldb

package
v0.6.4-rc3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2020 License: ISC Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Options is a function that returns a leveldb
	// opt.Options struct for opening a database.
	// It's defined as a variable for the sake of testing.
	Options = func() *opt.Options {
		return &defaultOptions
	}
)

Functions

This section is empty.

Types

type LevelDB

type LevelDB struct {
	// contains filtered or unexported fields
}

LevelDB defines a thin wrapper around leveldb.

func NewLevelDB

func NewLevelDB(path string) (*LevelDB, error)

NewLevelDB opens a leveldb instance defined by the given path.

func (*LevelDB) Begin

func (db *LevelDB) Begin() (*LevelDBTransaction, error)

Begin begins a new transaction.

func (*LevelDB) Close

func (db *LevelDB) Close() error

Close closes the leveldb instance.

func (*LevelDB) Cursor

func (db *LevelDB) Cursor(bucket *database.Bucket) *LevelDBCursor

Cursor begins a new cursor over the given prefix.

func (*LevelDB) Delete

func (db *LevelDB) Delete(key *database.Key) error

Delete deletes the value for the given key. Will not return an error if the key doesn't exist.

func (*LevelDB) Get

func (db *LevelDB) Get(key *database.Key) ([]byte, error)

Get gets the value for the given key. It returns ErrNotFound if the given key does not exist.

func (*LevelDB) Has

func (db *LevelDB) Has(key *database.Key) (bool, error)

Has returns true if the database does contains the given key.

func (*LevelDB) Put

func (db *LevelDB) Put(key *database.Key, value []byte) error

Put sets the value for the given key. It overwrites any previous value for that key.

type LevelDBCursor

type LevelDBCursor struct {
	// contains filtered or unexported fields
}

LevelDBCursor is a thin wrapper around native leveldb iterators.

func (*LevelDBCursor) Close

func (c *LevelDBCursor) Close() error

Close releases associated resources.

func (*LevelDBCursor) First

func (c *LevelDBCursor) First() bool

First moves the iterator to the first key/value pair. It returns false if such a pair does not exist. Panics if the cursor is closed.

func (*LevelDBCursor) Key

func (c *LevelDBCursor) Key() (*database.Key, error)

Key returns the key of the current key/value pair, or ErrNotFound if done. Note that the key is trimmed to not include the prefix the cursor was opened with. The caller should not modify the contents of the returned slice, and its contents may change on the next call to Next.

func (*LevelDBCursor) Next

func (c *LevelDBCursor) Next() bool

Next moves the iterator to the next key/value pair. It returns whether the iterator is exhausted. Panics if the cursor is closed.

func (*LevelDBCursor) Seek

func (c *LevelDBCursor) Seek(key *database.Key) error

Seek moves the iterator to the first key/value pair whose key is greater than or equal to the given key. It returns ErrNotFound if such pair does not exist.

func (*LevelDBCursor) Value

func (c *LevelDBCursor) Value() ([]byte, error)

Value returns the value of the current key/value pair, or ErrNotFound if done. The caller should not modify the contents of the returned slice, and its contents may change on the next call to Next.

type LevelDBTransaction

type LevelDBTransaction struct {
	// contains filtered or unexported fields
}

LevelDBTransaction is a thin wrapper around native leveldb batches and snapshots. It supports both get and put.

Snapshots provide a frozen view of the database at the moment the transaction begins. On the other hand, batches provide a mechanism to combine several database writes into one write, which seamlessly rolls back the database in case any individual write fails. Together the two forms a logic unit similar to what one might expect from a classic database transaction.

Note: Transactions provide data consistency over the state of the database as it was when the transaction started. As it's currently implemented, if one puts data into the transaction then it will not be available to get within the same transaction.

func (*LevelDBTransaction) Commit

func (tx *LevelDBTransaction) Commit() error

Commit commits whatever changes were made to the database within this transaction.

func (*LevelDBTransaction) Cursor

func (tx *LevelDBTransaction) Cursor(bucket *database.Bucket) (*LevelDBCursor, error)

Cursor begins a new cursor over the given bucket.

func (*LevelDBTransaction) Delete

func (tx *LevelDBTransaction) Delete(key *database.Key) error

Delete deletes the value for the given key. Will not return an error if the key doesn't exist.

func (*LevelDBTransaction) Get

func (tx *LevelDBTransaction) Get(key *database.Key) ([]byte, error)

Get gets the value for the given key. It returns ErrNotFound if the given key does not exist.

func (*LevelDBTransaction) Has

func (tx *LevelDBTransaction) Has(key *database.Key) (bool, error)

Has returns true if the database does contains the given key.

func (*LevelDBTransaction) Put

func (tx *LevelDBTransaction) Put(key *database.Key, value []byte) error

Put sets the value for the given key. It overwrites any previous value for that key.

func (*LevelDBTransaction) Rollback

func (tx *LevelDBTransaction) Rollback() error

Rollback rolls back whatever changes were made to the database within this transaction.

func (*LevelDBTransaction) RollbackUnlessClosed

func (tx *LevelDBTransaction) RollbackUnlessClosed() error

RollbackUnlessClosed rolls back changes that were made to the database within the transaction, unless the transaction had already been closed using either Rollback or Commit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL