ldb

package
v0.0.0-...-12ac4f6 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: ISC Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Options

func Options() opt.Options

Options is a function that returns a leveldb opt.Options struct for opening a database.

Types

type LevelDB

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

LevelDB defines a thin wrapper around leveldb.

func NewLevelDB

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

NewLevelDB opens a leveldb instance defined by the given path.

func (*LevelDB) Begin

func (db *LevelDB) Begin() (database.Transaction, error)

Begin begins a new transaction.

func (*LevelDB) Close

func (db *LevelDB) Close() error

Close closes the leveldb instance.

func (*LevelDB) Compact

func (db *LevelDB) Compact() error

Compact compacts the leveldb instance.

func (*LevelDB) Cursor

func (db *LevelDB) Cursor(bucket *database.Bucket) (database.Cursor, error)

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. It supports both get and put.

Note that reads are done from the Database directly, so if another transaction changed the data, you will read the new data, and not the one from the time the transaction was opened/

Note: 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) (database.Cursor, 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