Documentation ¶
Overview ¶
Package crkv is a client wrapping SQL interface, to provide a KV usage of cockroachdb
Index ¶
- type AmbiguousCommitError
- type By
- type CRKVStore
- func (kv *CRKVStore) Close() error
- func (kv *CRKVStore) Connect(url string)
- func (kv *CRKVStore) CreateDatabase(database string) error
- func (kv *CRKVStore) Del(ctx context.Context, key interface{}) error
- func (kv *CRKVStore) Get(ctx context.Context, key interface{}) (Value, error)
- func (kv *CRKVStore) Put(ctx context.Context, key interface{}, value interface{}) error
- func (kv *CRKVStore) Scan(ctx context.Context, begin, end interface{}, max int64) ([]KeyValuePair, error)
- func (kv *CRKVStore) Txn(ctx context.Context, fn func(ctx context.Context, txn Txn) error) (err error)
- type CRTxn
- type InmemKVStore
- func (kv *InmemKVStore) Del(ctx context.Context, key interface{}) error
- func (kv *InmemKVStore) Get(_ context.Context, key interface{}) (Value, error)
- func (kv *InmemKVStore) Put(_ context.Context, key interface{}, value interface{}) error
- func (kv *InmemKVStore) Scan(ctx context.Context, begin, end interface{}, max int64) ([]KeyValuePair, error)
- func (kv *InmemKVStore) Txn(ctx context.Context, fn func(ctx context.Context, txn Txn) error) error
- type InmemKeyValuePair
- type InmemTxn
- type Key
- type KeyValuePair
- type Option
- type Store
- type Txn
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AmbiguousCommitError ¶
type AmbiguousCommitError struct {
// contains filtered or unexported fields
}
AmbiguousCommitError represents an error that left a transaction in an ambiguous state: unclear if it committed or not.
type By ¶
type By func(kvp1, kvp2 KeyValuePair) bool
By is the type of a "less" function that defines the ordering of its KeyValuePair arguments.
func (By) Sort ¶
func (by By) Sort(kvps []KeyValuePair)
type CRKVStore ¶
CRKVStore is a cockroachdb store to manipulate key/values.
func NewKVStore ¶
NewKVStore returns a new KVStore connecting to url, default isolation level is serializable.
func (*CRKVStore) CreateDatabase ¶
CreateDatabase creates a new database.
func (*CRKVStore) Scan ¶
func (kv *CRKVStore) Scan(ctx context.Context, begin, end interface{}, max int64) ([]KeyValuePair, error)
Scan retrieves the key/value pairs between begin (inclusive) and end (exclusive) in ascending order.
func (*CRKVStore) Txn ¶
func (kv *CRKVStore) Txn(ctx context.Context, fn func(ctx context.Context, txn Txn) error) (err error)
Txn begins a txn running fn inside a transaction and retries it if needed. On non-retryable failures, the transaction is aborted and rolled back; on success, the transaction is committed. There are cases where the state of a transaction is inherently ambiguous: if we err on RELEASE with a communication error it's unclear if the transaction has been committed or not (similar to erroring on COMMIT in other databases). In that case, we return AmbiguousCommitError.
For more information about CockroachDB's transaction model see https://cockroachlabs.com/docs/transactions.html.
NOTE: the supplied exec closure should not have external side effects beyond changes to the database.
type CRTxn ¶
type CRTxn struct {
// contains filtered or unexported fields
}
CRTxn is an in-progress distributed database transaction.
type InmemKVStore ¶
type InmemKVStore struct { *memdb.MemDB // contains filtered or unexported fields }
InmemKVStore is based on github.com/ggaaooppeenngg/safemap key contains byte slice, it can not be a key in map, so use string instead as a key.
func (*InmemKVStore) Del ¶
func (kv *InmemKVStore) Del(ctx context.Context, key interface{}) error
Del deletes a value for a key.
func (*InmemKVStore) Get ¶
func (kv *InmemKVStore) Get(_ context.Context, key interface{}) (Value, error)
Get retrieves the value for a key.
func (*InmemKVStore) Put ¶
func (kv *InmemKVStore) Put(_ context.Context, key interface{}, value interface{}) error
Put sets a value for a key.
func (*InmemKVStore) Scan ¶
func (kv *InmemKVStore) Scan(ctx context.Context, begin, end interface{}, max int64) ([]KeyValuePair, error)
Scan retrieves the key/value pairs between begin (inclusive) and end (exclusive) in ascending order.
type InmemKeyValuePair ¶
type InmemTxn ¶
type InmemTxn struct { *memdb.Txn // contains filtered or unexported fields }
type KeyValuePair ¶
KeyValuePair represents a bytes key/valur pair.
type Option ¶
type Option func(kv *CRKVStore)
Option is a function to set KVStore option.
func SetIsolationLevel ¶
SetIsolationLevel sets default isolation level.
type Store ¶
type Store interface { Put(ctx context.Context, key interface{}, value interface{}) error Del(ctx context.Context, key interface{}) error Get(ctx context.Context, key interface{}) (Value, error) Scan(ctx context.Context, begin, end interface{}, max int64) ([]KeyValuePair, error) Txn(ctx context.Context, fn func(ctx context.Context, txn Txn) error) (err error) }
func NewInmemKVStore ¶
func NewInmemKVStore() Store