Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrKeyNotExist = errors.New("key does not exist")
ErrKeyNotExist is returned from DB.Get when retrieving a non-existing key.
Functions ¶
func AcceptanceTest ¶
AcceptanceTest is the acceptance test that all implementations of DB should pass. It should manually be called from a test case in each implementation:
func TestDB(t *testing.T) { db = NewDB() database.AcceptanceTest(t, db) }
func ContextWithTransaction ¶
func ContextWithTransaction(ctx context.Context, transaction Transaction) context.Context
ContextWithTransaction wraps ctx and returns a context that contains transaction.
Types ¶
type DB ¶
type DB interface { // NewTransaction starts and returns a new transaction. NewTransaction(ctx context.Context, update bool) (Transaction, context.Context, error) // Close should flush any cached writes, release all resources and close the // store. After Close is called other methods should return an error. Close() error // Ping pings the database and returns an error // if a connection to it is not possible. Ping(context.Context) error Set(ctx context.Context, key string, value []byte) error Get(ctx context.Context, key string) ([]byte, error) GetKeys(ctx context.Context, prefix string) ([]string, error) }
DB defines the interface for a key-value store.
type Transaction ¶
type Transaction interface { // Commit commits the transaction. If the transaction can't be committed // (e.g. read values were changed since the transaction started) it returns // an error. Commit() error // Discard discards a created transaction. This method is very important and // must be called. Calling this multiple times or after a Commit call // doesn't cause any issues, so this can safely be called via a defer right // when transaction is created. Discard() }
Transaction defines the interface for an isolated ACID DB transaction.
func TransactionFromContext ¶
func TransactionFromContext(ctx context.Context) Transaction
TransactionFromContext fetches the transaction from the context. If the context does not contain a transaction it returns nil.
Click to show internal directories.
Click to hide internal directories.