database

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotExist is returned from DB.Get when retrieving a non-existing key.
	ErrKeyNotExist = cerrors.New("key does not exist")
)

Functions

func AcceptanceTest

func AcceptanceTest(t *testing.T, db DB)

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)
}

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.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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