backend

package module
v0.0.0-...-7faf639 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2017 License: ISC Imports: 8 Imported by: 0

README

Backend GoDoc

WARNING: This software is new, experimental, and under heavy development. The documentation is lacking, if any. There are almost no tests. The APIs and source code layout can change in any moment. Do not trust it. Use it at your own risk.

You have been warned

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoltDB

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

BoltDB represents a key/value store.

func OpenBoltDB

func OpenBoltDB(path string, timeout time.Duration) (*BoltDB, error)

OpenBoltDB creates and opens a database at the given path. If the file does not exist then it will be created automatically.

Timeout is the amount of time to wait to obtain a file lock. When set to zero it will wait indefinitely. This option is only available on Darwin and Linux.

func (*BoltDB) Close

func (db *BoltDB) Close() error

func (*BoltDB) Iterator

func (db *BoltDB) Iterator() (Iterator, error)

func (*BoltDB) Name

func (db *BoltDB) Name() string

func (*BoltDB) Readonly

func (db *BoltDB) Readonly() (Txn, error)

func (*BoltDB) Writable

func (db *BoltDB) Writable() (RWTxn, error)

func (*BoltDB) WriteTo

func (db *BoltDB) WriteTo(w io.Writer) (n int64, err error)

type DB

type DB interface {
	// Iterator creates a iterator associated with the database.
	Iterator() (Iterator, error)

	// Readonly starts a new read-only transaction.  Starting multiple
	// read-only transaction will not block.
	Readonly() (Txn, error)

	// Writable starts a new transaction. Only one write transaction can be
	// used at a time. Starting multiple write transactions will cause the
	// calls to block and be serialized until the current write transaction
	// finishes.
	//
	// Transactions should not be dependent on one another.
	Writable() (RWTxn, error)

	// WriteTo writes the entire database to a writer.
	WriteTo(w io.Writer) (int64, error)

	// Name returns the unique database name.
	Name() string

	// Close closes the DB. It may or may not close any underlying io.Reader
	// or io.Writer, depending on how the DB was created.
	//
	// It is not safe to close a DB until all outstanding iterators and
	// transactions are closed. It is valid to call Close multiple times.
	// Other methods should not be called after the DB has been closed.
	Close() error
}

DB represents a key/value store.

type Error

type Error string

Error represents a database error.

const ErrNotFound Error = Error("key not found")

ErrNotFound means that a get or delete call did not find the requested key.

func (Error) Error

func (e Error) Error() string

type Iterator

type Iterator interface {
	// Seek moves the iterator to a given key and returns it. If the key
	// does not exist then the next key is used. If no keys follow, a nil
	// key is returned. The returned key and value are only valid for the
	// life of the transaction.
	Seek(key []byte) ([]byte, []byte)

	// First moves the iterator to the first item in the database and
	// returns its key and value. The returned key and value are only valid
	// for the life of the transaction.
	First() ([]byte, []byte)

	// Last moves the iterator to the last item in the database and
	// returns its key and value. The returned key and value are only valid
	// for the life of the transaction.
	Last() ([]byte, []byte)

	// Next moves the iterator to the next item in the database and returns
	// its key and value. If the iterator is at the end of the database
	// then a nil key and value are returned. The returned key and value
	// are only valid for the life of the transaction.
	Next() ([]byte, []byte)

	// Prev moves the iterator to the previous item in the database and
	// returns its key and value. If the iterator is at the beginning of
	// the database then a nil key and value are returned. The returned key
	// and value are only valid for the life of the transaction.
	Prev() ([]byte, []byte)

	// Close closes the iterator and returns any accumulated error.
	// Exhausting all the key/value pairs in a table is not considered to
	// be an error. It is valid to call Close multiple times. Other methods
	// should not be called after the iterator has been closed.
	Close() error
}

Iterator represents an iterator that can traverse over all key/value pairs in a database. Keys and values returned from the iterator are only valid for the life of the transaction. An iterator must be closed after use, but it is not necessary to read an iterator until exhaustion.

An iterator is not necessarily goroutine-safe, but it is safe to use multiple iterators concurrently, with each in a dedicated goroutine.

type LevelDB

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

func OpenLevelDB

func OpenLevelDB(root string, opts ...LevelOption) (*LevelDB, error)

func (*LevelDB) Close

func (db *LevelDB) Close() error

func (*LevelDB) Iterator

func (db *LevelDB) Iterator() (Iterator, error)

func (*LevelDB) Name

func (db *LevelDB) Name() string

func (*LevelDB) Readonly

func (db *LevelDB) Readonly() (Txn, error)

func (*LevelDB) Writable

func (db *LevelDB) Writable() (RWTxn, error)

func (*LevelDB) WriteTo

func (db *LevelDB) WriteTo(w io.Writer) (int64, error)

type LevelOption

type LevelOption func(*LevelDB) error

func BlockRestartInterval

func BlockRestartInterval(n int) LevelOption

func BlockSize

func BlockSize(size int) LevelOption

func WriteBufferSize

func WriteBufferSize(size int) LevelOption

type RWTxn

type RWTxn interface {
	Txn

	// Put sets the value for the given key. If the key exist then its
	// previous value will be overwritten. Supplied value must remain valid
	// for the life of the transaction.
	Put(key, value []byte) error

	// Delete deletes the value for the given key. If the key does not
	// exist then nothing is done and a nil error is returned.
	//
	// It is safe to modify the contents of the arguments after Delete
	// returns.
	Delete(key []byte) error

	// Commit write all changes.
	Commit() error
}

RWTxn represents a read/write transaction on the database.

type Txn

type Txn interface {
	// Get gets the value for the given key. It returns ErrNotFound if the
	// database does not contain the key.
	//
	// The caller should not modify the contents of the returned slice, but
	// it is safe to modify the contents of the argument after Get returns.
	Get(key []byte) ([]byte, error)

	// Rollback closes the transaction and ignores all previous updates.
	Rollback() error
}

Txn represents a read-only transaction on the database.

Jump to

Keyboard shortcuts

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