kvstore

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyPrefix    = "K$"
	KeyMaxLength = 8 << 10

	FieldPrefix = "F$"

	MaxBatchKeys = 8 << 10 // TODO not implemented
)
View Source
const StoreSuffix = ".store"

Variables

View Source
var DefaultWriteOptions = &pebble.WriteOptions{
	Sync: false,
}
View Source
var DefaultWriteSyncOptions = &pebble.WriteOptions{
	Sync: true,
}
View Source
var ErrKeyTooLong = errors.New("too long key")
View Source
var ErrSkip = errors.New("skip") // skip count in iterator
View Source
var ErrTableClosed = errors.New("table closed")
View Source
var ErrTableNotFound = errors.New("table not found")

Functions

func IsNotFound added in v1.3.5

func IsNotFound(err error) bool

func IsSkipError added in v1.3.5

func IsSkipError(err error) bool

func IsValidName

func IsValidName(name string) bool

IsValidName check if store name or database name or table name is valid

func NewTableClosedErr added in v1.3.5

func NewTableClosedErr(tableName string) error

func RemoveStore

func RemoveStore(path string) error

RemoveStore remove store directory

func Skip added in v1.3.5

func Skip() (bool, error)

Types

type BaseObjectEncoder

type BaseObjectEncoder[T any] struct {
}

func (*BaseObjectEncoder[T]) Decode

func (this *BaseObjectEncoder[T]) Decode(valueData []byte) (value T, err error)

func (*BaseObjectEncoder[T]) Encode

func (this *BaseObjectEncoder[T]) Encode(value T) ([]byte, error)

type BoolValueEncoder

type BoolValueEncoder[T bool] struct {
}

func NewBoolValueEncoder

func NewBoolValueEncoder[T bool]() *BoolValueEncoder[T]

func (*BoolValueEncoder[T]) Decode

func (this *BoolValueEncoder[T]) Decode(valueData []byte) (value T, err error)

func (*BoolValueEncoder[T]) Encode

func (this *BoolValueEncoder[T]) Encode(value T) ([]byte, error)

func (*BoolValueEncoder[T]) EncodeField

func (this *BoolValueEncoder[T]) EncodeField(value T, fieldName string) ([]byte, error)

type BytesValueEncoder

type BytesValueEncoder[T []byte] struct {
}

func NewBytesValueEncoder

func NewBytesValueEncoder[T []byte]() *BytesValueEncoder[T]

func (*BytesValueEncoder[T]) Decode

func (this *BytesValueEncoder[T]) Decode(valueData []byte) (value T, err error)

func (*BytesValueEncoder[T]) Encode

func (this *BytesValueEncoder[T]) Encode(value T) ([]byte, error)

func (*BytesValueEncoder[T]) EncodeField

func (this *BytesValueEncoder[T]) EncodeField(value T, fieldName string) ([]byte, error)

type CounterTable

type CounterTable[T int64 | uint64] struct {
	*Table[T]
}

func NewCounterTable

func NewCounterTable[T int64 | uint64](name string) (*CounterTable[T], error)

func (*CounterTable[T]) Increase

func (this *CounterTable[T]) Increase(key string, delta T) (newValue T, err error)

type DB

type DB struct {
	// contains filtered or unexported fields
}

func NewDB

func NewDB(store *Store, dbName string) (*DB, error)

func (*DB) AddTable

func (this *DB) AddTable(table TableInterface)

func (*DB) Close

func (this *DB) Close() error

func (*DB) Inspect added in v1.3.5

func (this *DB) Inspect(fn func(key []byte, value []byte)) error

func (*DB) Name

func (this *DB) Name() string

func (*DB) Namespace

func (this *DB) Namespace() string

func (*DB) Store

func (this *DB) Store() *Store

func (*DB) Truncate added in v1.3.5

func (this *DB) Truncate() error

Truncate the database

type DataType

type DataType = int
const (
	DataTypeKey   DataType = 1
	DataTypeField DataType = 2
)

type IntValueEncoder

type IntValueEncoder[T constraints.Integer] struct {
}

func NewIntValueEncoder

func NewIntValueEncoder[T constraints.Integer]() *IntValueEncoder[T]

func (*IntValueEncoder[T]) Decode

func (this *IntValueEncoder[T]) Decode(valueData []byte) (value T, err error)

func (*IntValueEncoder[T]) Encode

func (this *IntValueEncoder[T]) Encode(value T) (data []byte, err error)

func (*IntValueEncoder[T]) EncodeField

func (this *IntValueEncoder[T]) EncodeField(value T, fieldName string) ([]byte, error)

type Item

type Item[T any] struct {
	Key      string
	Value    T
	FieldKey []byte
}

type IteratorFunc

type IteratorFunc[T any] func(tx *Tx[T], item Item[T]) (goNext bool, err error)

type IteratorOptions

type IteratorOptions struct {
	LowerBound []byte
	UpperBound []byte
}

func (*IteratorOptions) RawOptions

func (this *IteratorOptions) RawOptions() *pebble.IterOptions

type Logger

type Logger struct {
}

func NewLogger

func NewLogger() *Logger

func (*Logger) Errorf added in v1.3.7

func (this *Logger) Errorf(format string, args ...any)

func (*Logger) Fatalf

func (this *Logger) Fatalf(format string, args ...any)

func (*Logger) Infof

func (this *Logger) Infof(format string, args ...any)

type NilValueEncoder added in v1.3.5

type NilValueEncoder[T []byte] struct {
}

func NewNilValueEncoder added in v1.3.5

func NewNilValueEncoder[T []byte]() *NilValueEncoder[T]

func (*NilValueEncoder[T]) Decode added in v1.3.5

func (this *NilValueEncoder[T]) Decode(valueData []byte) (value T, err error)

func (*NilValueEncoder[T]) Encode added in v1.3.5

func (this *NilValueEncoder[T]) Encode(value T) ([]byte, error)

func (*NilValueEncoder[T]) EncodeField added in v1.3.5

func (this *NilValueEncoder[T]) EncodeField(value T, fieldName string) ([]byte, error)

type Query

type Query[T any] struct {
	// contains filtered or unexported fields
}

func NewQuery

func NewQuery[T any]() *Query[T]

func (*Query[T]) Desc

func (this *Query[T]) Desc() *Query[T]

func (*Query[T]) FieldAsc

func (this *Query[T]) FieldAsc(fieldName string) *Query[T]

func (*Query[T]) FieldDesc

func (this *Query[T]) FieldDesc(fieldName string) *Query[T]

func (*Query[T]) FieldOffset

func (this *Query[T]) FieldOffset(fieldOffset []byte) *Query[T]

func (*Query[T]) FieldPrefix

func (this *Query[T]) FieldPrefix(fieldName string, fieldPrefix string) *Query[T]

func (*Query[T]) FindAll

func (this *Query[T]) FindAll(fn IteratorFunc[T]) (err error)

func (*Query[T]) ForField

func (this *Query[T]) ForField() *Query[T]

func (*Query[T]) ForKey

func (this *Query[T]) ForKey() *Query[T]

func (*Query[T]) ForUpdate

func (this *Query[T]) ForUpdate() *Query[T]

func (*Query[T]) KeysOnly

func (this *Query[T]) KeysOnly() *Query[T]

func (*Query[T]) Limit

func (this *Query[T]) Limit(limit int) *Query[T]

func (*Query[T]) Offset

func (this *Query[T]) Offset(offsetKey string) *Query[T]

func (*Query[T]) Prefix

func (this *Query[T]) Prefix(prefix string) *Query[T]

func (*Query[T]) SetTable

func (this *Query[T]) SetTable(table *Table[T]) *Query[T]

func (*Query[T]) SetTx

func (this *Query[T]) SetTx(tx *Tx[T]) *Query[T]

type QueryOperator

type QueryOperator int
const (
	QueryOperatorGt  QueryOperator = 1
	QueryOperatorGte QueryOperator = 2
	QueryOperatorLt  QueryOperator = 3
	QueryOperatorLte QueryOperator = 4
)

type QueryOperatorInfo

type QueryOperatorInfo struct {
	Operator QueryOperator
	Value    any
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

func DefaultStore added in v1.3.5

func DefaultStore() (*Store, error)

func NewStore

func NewStore(storeName string) (*Store, error)

NewStore create store with name

func NewStoreWithPath added in v1.3.7

func NewStoreWithPath(path string) (*Store, error)

NewStoreWithPath create store with path

func OpenStore

func OpenStore(storeName string) (*Store, error)

func OpenStoreDir

func OpenStoreDir(dir string, storeName string) (*Store, error)

func (*Store) Close

func (this *Store) Close() error

func (*Store) Delete

func (this *Store) Delete(keyBytes []byte) error

func (*Store) Flush added in v1.3.5

func (this *Store) Flush() error

func (*Store) Get

func (this *Store) Get(keyBytes []byte) (valueBytes []byte, closer io.Closer, err error)

func (*Store) IsClosed

func (this *Store) IsClosed() bool

func (*Store) NewDB

func (this *Store) NewDB(dbName string) (*DB, error)

func (*Store) Open

func (this *Store) Open() error

func (*Store) Path added in v1.3.7

func (this *Store) Path() string

func (*Store) RawDB

func (this *Store) RawDB() *pebble.DB

func (*Store) Set

func (this *Store) Set(keyBytes []byte, valueBytes []byte) error

type StringValueEncoder

type StringValueEncoder[T string] struct {
}

func NewStringValueEncoder

func NewStringValueEncoder[T string]() *StringValueEncoder[T]

func (*StringValueEncoder[T]) Decode

func (this *StringValueEncoder[T]) Decode(valueData []byte) (value T, err error)

func (*StringValueEncoder[T]) Encode

func (this *StringValueEncoder[T]) Encode(value T) ([]byte, error)

func (*StringValueEncoder[T]) EncodeField

func (this *StringValueEncoder[T]) EncodeField(value T, fieldName string) ([]byte, error)

type Table

type Table[T any] struct {
	// contains filtered or unexported fields
}

func NewTable

func NewTable[T any](tableName string, encoder ValueEncoder[T]) (*Table[T], error)

func (*Table[T]) AddField

func (this *Table[T]) AddField(fieldName string) error

func (*Table[T]) AddFields

func (this *Table[T]) AddFields(fieldName ...string) error

func (*Table[T]) Close

func (this *Table[T]) Close() error

func (*Table[T]) ComposeFieldKey

func (this *Table[T]) ComposeFieldKey(keyBytes []byte, fieldName string, fieldValueBytes []byte) []byte

ComposeFieldKey compose field key $Namespace$FieldName$FieldValueSeparatorKeyValueFieldLength[2]

func (*Table[T]) Count

func (this *Table[T]) Count() (int64, error)

func (*Table[T]) DB

func (this *Table[T]) DB() *DB

func (*Table[T]) DecodeFieldKey

func (this *Table[T]) DecodeFieldKey(fieldName string, fieldKey []byte) (fieldValue []byte, key []byte, err error)

func (*Table[T]) Delete

func (this *Table[T]) Delete(key ...string) error

func (*Table[T]) DeleteRange added in v1.3.5

func (this *Table[T]) DeleteRange(start string, end string) error

func (*Table[T]) DropField

func (this *Table[T]) DropField(fieldName string) error

func (*Table[T]) Encoder added in v1.3.5

func (this *Table[T]) Encoder() ValueEncoder[T]

func (*Table[T]) Exist

func (this *Table[T]) Exist(key string) (found bool, err error)

func (*Table[T]) FieldKey

func (this *Table[T]) FieldKey(fieldName string) []byte

func (*Table[T]) FullKey

func (this *Table[T]) FullKey(realKey string) []byte

func (*Table[T]) FullKeyBytes

func (this *Table[T]) FullKeyBytes(realKeyBytes []byte) []byte

func (*Table[T]) Get

func (this *Table[T]) Get(key string) (value T, err error)

func (*Table[T]) Insert added in v1.3.5

func (this *Table[T]) Insert(key string, value T) error

func (*Table[T]) Name

func (this *Table[T]) Name() string

func (*Table[T]) Namespace

func (this *Table[T]) Namespace() []byte

func (*Table[T]) Query

func (this *Table[T]) Query() *Query[T]

func (*Table[T]) ReadTx

func (this *Table[T]) ReadTx(fn func(tx *Tx[T]) error) error

func (*Table[T]) Set

func (this *Table[T]) Set(key string, value T) error

func (*Table[T]) SetDB

func (this *Table[T]) SetDB(db *DB)

func (*Table[T]) SetNamespace

func (this *Table[T]) SetNamespace(namespace []byte)

func (*Table[T]) SetSync added in v1.3.5

func (this *Table[T]) SetSync(key string, value T) error

func (*Table[T]) Truncate

func (this *Table[T]) Truncate() error

func (*Table[T]) WriteTx

func (this *Table[T]) WriteTx(fn func(tx *Tx[T]) error) error

func (*Table[T]) WriteTxSync added in v1.3.5

func (this *Table[T]) WriteTxSync(fn func(tx *Tx[T]) error) error

type TableInterface

type TableInterface interface {
	Name() string
	SetNamespace(namespace []byte)
	SetDB(db *DB)
	Close() error
}

type Tx

type Tx[T any] struct {
	// contains filtered or unexported fields
}

func NewTx

func NewTx[T any](table *Table[T], readOnly bool) (*Tx[T], error)

func (*Tx[T]) Close

func (this *Tx[T]) Close() error

func (*Tx[T]) Commit

func (this *Tx[T]) Commit() (err error)

func (*Tx[T]) CommitSync added in v1.3.5

func (this *Tx[T]) CommitSync() (err error)

func (*Tx[T]) Delete

func (this *Tx[T]) Delete(key string) error

func (*Tx[T]) Get

func (this *Tx[T]) Get(key string) (value T, err error)

func (*Tx[T]) Insert added in v1.3.5

func (this *Tx[T]) Insert(key string, value T) error

func (*Tx[T]) NewIterator

func (this *Tx[T]) NewIterator(opt *IteratorOptions) (*pebble.Iterator, error)

func (*Tx[T]) Query

func (this *Tx[T]) Query() *Query[T]

func (*Tx[T]) Set

func (this *Tx[T]) Set(key string, value T) error

func (*Tx[T]) SetSync added in v1.3.5

func (this *Tx[T]) SetSync(key string, value T) error

type ValueEncoder

type ValueEncoder[T any] interface {
	Encode(value T) ([]byte, error)
	EncodeField(value T, fieldName string) ([]byte, error)
	Decode(valueBytes []byte) (value T, err error)
}

Jump to

Keyboard shortcuts

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