Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrKeyNotExists = errors.New("specified key does not exists") ErrKeyNotFound = errors.New("key not found") ErrTransactionExists = errors.New("can not create two transactions") ErrTransactionClosed = errors.New("the transaction is closed") ErrDatabasePanic = errors.New("database panic") ErrOnlySupportBatchOpt = errors.New("flush is only for batch opt") )
error
Functions ¶
Types ¶
type Batch ¶
type Batch interface { // put the value to entry associate with the key Put(key, value []byte) // delete the entry associate with the key in the Storage Del(key []byte) // remove all the enqueued put/delete Clear() // returns the number of updates in the batch Count() int // atomic writes all enqueued put/delete Write() error // close the batch, it must be called to close the batch Close() }
Batch defines the batch of put, del operations
type Config ¶
type Config struct { Name string `mapstructure:"name"` Path string `mapstructure:"path"` Options Options `mapstructure:"options"` }
Config defines the database configuration
type Database ¶
type Database struct { Storage // contains filtered or unexported fields }
Database is a wrapper of Storage, implementing the database life cycle
func NewDatabase ¶
NewDatabase creates a database instance
type Operations ¶
Operations defines common data operations on database/table
type Reader ¶
type Reader interface { // return value associate with the key in the Storage Get(key []byte) ([]byte, error) // return values associate with the keys in the Storage MultiGet(key ...[]byte) ([][]byte, error) // check if the entry associate with key exists Has(key []byte) (bool, error) // return a set of keys in the Storage Keys() [][]byte // return a chan to iter all keys IterKeys(ctx context.Context) <-chan []byte // return a set of keys with specified prefix in the Storage KeysWithPrefix(prefix []byte) [][]byte // return a chan to iter all keys with specified prefix IterKeysWithPrefix(ctx context.Context, prefix []byte) <-chan []byte }
Reader defines common read operations on database/table
type Storage ¶
type Storage interface { Table // Create or Get the table associated with the name Table(string) (Table, error) DropTable(string) error Close() error }
Storage defines the data persistence methods
type Table ¶
type Table interface { Operations EnableBatch() DisableBatch() IsInBatch() bool Flush() error // NewTransaction creates a new transaction on the Storage. NewTransaction() (Transaction, error) }
Table defines all methods of database table.
type Transaction ¶
type Transaction interface { Operations // Commit finalizes a transaction, attempting to commit it to the Storage. Commit() error // Discard throws away changes recorded in a transaction without committing. // them to the underlying Storage. Any calls made to Discard after Commit // has been successfully called will have no effect on the transaction and // state of the Storage, making it safe to defer. Discard() }
Transaction allow user to read/write Storage atomicly. Actions performed on a transaction will not take hold until a successful call to Commit has been made.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.