gokv

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: GPL-3.0 Imports: 1 Imported by: 2

README

gokv

this is a fork of https://github.com/philippgille/gokv

the bad things are removed

forking off because i am very picky.

store will aim to stay compatible

documentation is incomplete, ignore it and read the code. sorry!

this uses go workspaces. i don't really know how it works lol

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComplexRoStore added in v0.0.2

type ComplexRoStore interface {
	RoStore

	ForEach(fromPrefix string, walker func(k, v []byte) error) error
	ForPrefix(prefix string, walker func(k, v []byte) error) error
	ForAmount(prefix string, amount uint32, walker func(k, v []byte) error) error

	View(ctx context.Context, f func(tx RoTx) error) error
	BeginRo(ctx context.Context) (RoTx, error)
}

type ComplexStore added in v0.0.2

type ComplexStore interface {
	Store
	ComplexRoStore

	Update(ctx context.Context, f func(tx Tx) error) error
	BeginRw(ctx context.Context) (Tx, error)
}

type Cursor added in v0.0.2

type Cursor interface {
	RoCursor

	Put(k string, v []byte) error // Put - based on order
	Delete(k string) error        // Delete - short version of SeekExact+DeleteCurrent or SeekBothExact+DeleteCurrent
	DeleteCurrent() error
}

type PrefixIterator added in v0.0.2

type PrefixIterator interface {
	Next() bool
	Get(v any) (k string, err error)
}

type PrefixStore added in v0.0.2

type PrefixStore interface {
	Store

	// create an iterator with k as the prefix
	GetPrefix(k string) (PrefixIterator, error)
}

Prefix store is a store that allows retreival by prefix

type RoCursor added in v0.0.2

type RoCursor interface {
	First() (string, []byte, error)               // First - position at first key/data item
	Seek(seek string) (string, []byte, error)     // Seek - position at first key greater than or equal to specified key
	SeekExact(key string) (string, []byte, error) // SeekExact - position at exact matching key if exists
	Next() (string, []byte, error)                // Next - position at next key/value (can iterate over DupSort key/values automatically)
	Prev() (string, []byte, error)                // Prev - position at previous key
	Last() (string, []byte, error)                // Last - position at last key and last possible value
	Current() (string, []byte, error)             // Current - return key/data at current cursor position

	Count() (uint64, error) // Count

	Close()
}

type RoStore added in v0.0.2

type RoStore interface {
	Get(k string, v any) (found bool, err error)
	Close() error
}

type RoTx added in v0.0.2

type RoTx interface {
	StatelessReadTx

	ViewID() uint64
	Cursor(bucket string) (Cursor, error)
	DBSize() (uint64, error)
}

type StatelessReadTx added in v0.0.2

type StatelessReadTx interface {
	ComplexRoStore

	Commit() error
	Rollback()
	Size() (uint64, error)
}

type StatelessTx added in v0.0.2

type StatelessTx interface {
	ComplexStore

	IncrementSequence(key string, amount uint64) (uint64, error)
	Append(k []string, v []byte) error
}

type Store

type Store interface {
	// Set stores the given value for the given key.
	// The implementation automatically marshalls the value.
	// The marshalling format depends on the implementation. It can be JSON, gob etc.
	// The key must not be "" and the value must not be nil.
	Set(k string, v any) error
	// Get retrieves the value for the given key.
	// The implementation automatically unmarshalls the value.
	// The unmarshalling source depends on the implementation. It can be JSON, gob etc.
	// The automatic unmarshalling requires a pointer to an object of the correct type
	// being passed as parameter.
	// In case of a struct the Get method will populate the fields of the object
	// that the passed pointer points to with the values of the retrieved object's values.
	// If no value is found it returns (false, nil).
	// The key must not be "" and the pointer must not be nil.
	Get(k string, v any) (found bool, err error)
	// Delete deletes the stored value for the given key.
	// Deleting a non-existing key-value pair does NOT lead to an error.
	// The key must not be "".
	Delete(k string) error
	// Close must be called when the work with the key-value store is done.
	// Most (if not all) implementations are meant to be used long-lived,
	// so only call Close() at the very end.
	// Depending on the store implementation it might do one or more of the following:
	// Make sure all pending updates make their way to disk,
	// finish open transactions,
	// close the file handle to an embedded DB,
	// close the connection to the DB server,
	// release any open resources,
	// etc.
	// Some implementation might not need the store to be closed,
	// but as long as you work with the gokv.Store interface you never know which implementation
	// is passed to your method, so you should always call it.
	Close() error
}

Store is an abstraction for different key-value store implementations. A store must be able to store, retrieve and delete key-value pairs, with the key being a string and the value being any Go any.

type Tx added in v0.0.2

type Tx interface {
	RoTx
	StatelessTx

	RwCursor() (Cursor, error)
	Reset() error
}

Directories

Path Synopsis
arangodb module
cockroachdb module
encoding module
file module
redis module
sql module
syncmap module
test module
util module

Jump to

Keyboard shortcuts

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