kv

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotFound = &KeyNotFoundError{}

ErrKeyNotFound is returned when a key doesn't exist

View Source
var ErrNestedTransaction = &NestedTransactionError{}

ErrNestedTransaction is returned when attempting to create nested transactions

Functions

func CreatePool

func CreatePool(dataPath, metaPath string) error

CreatePool initializes the global KV store pool

func DrainPool

func DrainPool() error

DrainPool closes the global pool

func IndexKey

func IndexKey(tableName, indexName, value string, primaryKey string) []byte

IndexKey generates keys for secondary indexes

func ParseTableRowKey

func ParseTableRowKey(key []byte) (tableName, rowID string, valid bool)

ParseTableRowKey extracts table name and row ID from a table row key

func VersionKey

func VersionKey(baseKey []byte, version uint64) []byte

VersionKey generates keys for versioned data

Types

type BadgerBatch

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

BadgerBatch implements atomic batch operations

func (*BadgerBatch) Delete

func (b *BadgerBatch) Delete(key []byte) error

func (*BadgerBatch) Flush

func (b *BadgerBatch) Flush() error

func (*BadgerBatch) Reset

func (b *BadgerBatch) Reset()

func (*BadgerBatch) Set

func (b *BadgerBatch) Set(key, value []byte) error

type BadgerItem

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

BadgerItem wraps BadgerDB item

func (*BadgerItem) Key

func (i *BadgerItem) Key() []byte

func (*BadgerItem) KeyCopy

func (i *BadgerItem) KeyCopy() []byte

func (*BadgerItem) Value

func (i *BadgerItem) Value() ([]byte, error)

func (*BadgerItem) ValueCopy

func (i *BadgerItem) ValueCopy() ([]byte, error)

type BadgerIterator

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

BadgerIterator wraps BadgerDB iterator

func (*BadgerIterator) Close

func (i *BadgerIterator) Close() error

func (*BadgerIterator) Item

func (i *BadgerIterator) Item() Item

func (*BadgerIterator) Next

func (i *BadgerIterator) Next()

func (*BadgerIterator) Rewind

func (i *BadgerIterator) Rewind()

func (*BadgerIterator) Seek

func (i *BadgerIterator) Seek(key []byte)

func (*BadgerIterator) Valid

func (i *BadgerIterator) Valid() bool

type BadgerStore

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

BadgerStore implements Store interface using BadgerDB

func NewBadgerStore

func NewBadgerStore(path string) (*BadgerStore, error)

NewBadgerStore creates a new BadgerDB-backed store

func (*BadgerStore) Begin

func (s *BadgerStore) Begin(writable bool) (Transaction, error)

func (*BadgerStore) Close

func (s *BadgerStore) Close() error

func (*BadgerStore) Delete

func (s *BadgerStore) Delete(ctx context.Context, key []byte) error

func (*BadgerStore) Get

func (s *BadgerStore) Get(ctx context.Context, key []byte) ([]byte, error)

func (*BadgerStore) NewBatch

func (s *BadgerStore) NewBatch() Batch

func (*BadgerStore) NewIterator

func (s *BadgerStore) NewIterator(opts IteratorOptions) Iterator

func (*BadgerStore) Put

func (s *BadgerStore) Put(ctx context.Context, key, value []byte) error

func (*BadgerStore) Size

func (s *BadgerStore) Size() (int64, error)

func (*BadgerStore) Sync

func (s *BadgerStore) Sync() error

type BadgerTransaction

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

BadgerTransaction wraps BadgerDB transaction

func (*BadgerTransaction) Begin

func (t *BadgerTransaction) Begin(writable bool) (Transaction, error)

func (*BadgerTransaction) Close

func (t *BadgerTransaction) Close() error

func (*BadgerTransaction) Commit

func (t *BadgerTransaction) Commit() error

func (*BadgerTransaction) Delete

func (t *BadgerTransaction) Delete(ctx context.Context, key []byte) error

func (*BadgerTransaction) Discard

func (t *BadgerTransaction) Discard()

func (*BadgerTransaction) Get

func (t *BadgerTransaction) Get(ctx context.Context, key []byte) ([]byte, error)

func (*BadgerTransaction) NewBatch

func (t *BadgerTransaction) NewBatch() Batch

func (*BadgerTransaction) NewIterator

func (t *BadgerTransaction) NewIterator(opts IteratorOptions) Iterator

func (*BadgerTransaction) Put

func (t *BadgerTransaction) Put(ctx context.Context, key, value []byte) error

func (*BadgerTransaction) Size

func (t *BadgerTransaction) Size() (int64, error)

func (*BadgerTransaction) Sync

func (t *BadgerTransaction) Sync() error

type BadgerTxnBatch

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

BadgerTxnBatch implements batch operations within a transaction

func (*BadgerTxnBatch) Delete

func (b *BadgerTxnBatch) Delete(key []byte) error

func (*BadgerTxnBatch) Flush

func (b *BadgerTxnBatch) Flush() error

func (*BadgerTxnBatch) Reset

func (b *BadgerTxnBatch) Reset()

func (*BadgerTxnBatch) Set

func (b *BadgerTxnBatch) Set(key, value []byte) error

type Batch

type Batch interface {
	Set(key, value []byte) error
	Delete(key []byte) error
	Flush() error
	Reset()
}

Batch provides atomic batch operations

type Item

type Item interface {
	Key() []byte
	KeyCopy() []byte
	Value() ([]byte, error)
	ValueCopy() ([]byte, error)
}

Item represents a key-value pair during iteration

type Iterator

type Iterator interface {
	io.Closer

	// Navigation
	Rewind()
	Seek(key []byte)
	Next()
	Valid() bool

	// Data access
	Item() Item
}

Iterator provides ordered key-value iteration

type IteratorOptions

type IteratorOptions struct {
	Prefix         []byte
	Reverse        bool
	PrefetchValues bool
	PrefetchSize   int
}

IteratorOptions configures iteration behavior

type KeyBuilder

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

KeyBuilder helps construct hierarchical keys for different data types

func NewKeyBuilder

func NewKeyBuilder() *KeyBuilder

NewKeyBuilder creates a new key builder

func (*KeyBuilder) Append

func (kb *KeyBuilder) Append(part string) *KeyBuilder

Append adds a custom part to the key

func (*KeyBuilder) Build

func (kb *KeyBuilder) Build() []byte

Build constructs the final key as bytes

func (*KeyBuilder) Clone

func (kb *KeyBuilder) Clone() *KeyBuilder

Clone creates a copy of the KeyBuilder

func (*KeyBuilder) Index

func (kb *KeyBuilder) Index(indexName string) *KeyBuilder

Index adds index information to the key

func (*KeyBuilder) Meta

func (kb *KeyBuilder) Meta() *KeyBuilder

Meta adds metadata namespace to the key

func (*KeyBuilder) Migration

func (kb *KeyBuilder) Migration(migrationID string) *KeyBuilder

Migration adds migration information to the key

func (*KeyBuilder) Node

func (kb *KeyBuilder) Node(nodeID string) *KeyBuilder

Node adds node information to the key

func (*KeyBuilder) Ownership

func (kb *KeyBuilder) Ownership(tableName string) *KeyBuilder

Ownership adds ownership information to the key

func (*KeyBuilder) Row

func (kb *KeyBuilder) Row(rowID string) *KeyBuilder

Row adds a row identifier to the key

func (*KeyBuilder) Schema

func (kb *KeyBuilder) Schema(tableName string) *KeyBuilder

Schema adds schema information to the key

func (*KeyBuilder) String

func (kb *KeyBuilder) String() string

String returns the key as a string (for debugging)

func (*KeyBuilder) Table

func (kb *KeyBuilder) Table(tableName string) *KeyBuilder

Table adds a table namespace to the key

type KeyNotFoundError

type KeyNotFoundError struct{}

func (*KeyNotFoundError) Error

func (e *KeyNotFoundError) Error() string

type NestedTransactionError

type NestedTransactionError struct{}

func (*NestedTransactionError) Error

func (e *NestedTransactionError) Error() string

type Pool

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

Pool manages multiple key-value store instances

func GetPool

func GetPool() *Pool

GetPool returns the global pool instance

func NewPool

func NewPool(dataPath, metaPath string) (*Pool, error)

NewPool creates a new pool with data and metadata stores

func (*Pool) BackgroundMaintenance

func (p *Pool) BackgroundMaintenance(ctx context.Context)

BackgroundMaintenance runs periodic maintenance tasks

func (*Pool) Close

func (p *Pool) Close() error

Close closes all stores in the pool

func (*Pool) DataStore

func (p *Pool) DataStore() Store

DataStore returns the main data store

func (*Pool) MetaStore

func (p *Pool) MetaStore() Store

MetaStore returns the metadata store

func (*Pool) NewDataConnection

func (p *Pool) NewDataConnection(ctx context.Context, writable bool) (*StoreConnection, error)

NewDataConnection creates a connection to the data store

func (*Pool) NewMetaConnection

func (p *Pool) NewMetaConnection(ctx context.Context, writable bool) (*StoreConnection, error)

NewMetaConnection creates a connection to the metadata store

func (*Pool) Size

func (p *Pool) Size() (dataSize, metaSize int64, err error)

Size returns the total size of all stores

func (*Pool) Sync

func (p *Pool) Sync() error

Sync synchronizes both stores to disk

type Record

type Record struct {
	Fields  map[string]*Value `json:"fields"`
	Version uint64            `json:"version"`
	Created time.Time         `json:"created"`
	Updated time.Time         `json:"updated"`
}

Record represents a collection of named values (equivalent to a SQL row)

func DecodeRecord

func DecodeRecord(data []byte) (*Record, error)

DecodeRecord deserializes bytes back to a Record

func NewRecord

func NewRecord() *Record

NewRecord creates a new record

func (*Record) Encode

func (r *Record) Encode() ([]byte, error)

Encode serializes the record to bytes

func (*Record) GetField

func (r *Record) GetField(name string) (*Value, bool)

GetField gets a field value

func (*Record) SetField

func (r *Record) SetField(name string, value *Value)

SetField sets a field value

type Store

type Store interface {
	// Basic operations
	Get(ctx context.Context, key []byte) ([]byte, error)
	Put(ctx context.Context, key, value []byte) error
	Delete(ctx context.Context, key []byte) error

	// Batch operations for atomic writes
	NewBatch() Batch

	// Iteration support for range queries
	NewIterator(opts IteratorOptions) Iterator

	// Transaction support
	Begin(writable bool) (Transaction, error)

	// Lifecycle
	Close() error

	// Statistics and maintenance
	Size() (int64, error)
	Sync() error
}

Store defines the key-value storage interface for Atlas-DB

type StoreConnection

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

StoreConnection represents a connection to a specific store

func (*StoreConnection) Close

func (c *StoreConnection) Close() error

Close discards the transaction (alias for Rollback)

func (*StoreConnection) Commit

func (c *StoreConnection) Commit() error

Commit commits the transaction

func (*StoreConnection) Rollback

func (c *StoreConnection) Rollback()

Rollback discards the transaction

func (*StoreConnection) Store

func (c *StoreConnection) Store() Store

Store returns the underlying store

func (*StoreConnection) Transaction

func (c *StoreConnection) Transaction() Transaction

Transaction returns the active transaction

type Transaction

type Transaction interface {
	Store
	Commit() error
	Discard()
}

Transaction provides ACID transaction support

type TypeCode

type TypeCode int

TypeCode represents the data type

const (
	TypeString TypeCode = iota + 1
	TypeInt
	TypeFloat
	TypeBool
	TypeBlob
	TypeNull
	TypeTime
	TypeDuration
	TypeJSON
)

func (TypeCode) String

func (tc TypeCode) String() string

String returns the string representation of TypeCode

type Value

type Value struct {
	Type     TypeCode               `json:"type"`
	Data     interface{}            `json:"data"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

Value represents a typed value that can be stored in the KV store

func DecodeValue

func DecodeValue(data []byte) (*Value, error)

DecodeValue deserializes bytes back to a Value

func NewBlobValue

func NewBlobValue(data []byte) *Value

NewBlobValue creates a blob value

func NewBoolValue

func NewBoolValue(b bool) *Value

NewBoolValue creates a boolean value

func NewDurationValue

func NewDurationValue(d time.Duration) *Value

NewDurationValue creates a duration value

func NewFloatValue

func NewFloatValue(f float64) *Value

NewFloatValue creates a float value

func NewIntValue

func NewIntValue(i int64) *Value

NewIntValue creates an integer value

func NewJSONValue

func NewJSONValue(data interface{}) *Value

NewJSONValue creates a JSON value

func NewNullValue

func NewNullValue() *Value

NewNullValue creates a null value

func NewStringValue

func NewStringValue(s string) *Value

NewStringValue creates a string value

func NewTimeValue

func NewTimeValue(t time.Time) *Value

NewTimeValue creates a time value

func (*Value) Encode

func (v *Value) Encode() ([]byte, error)

Encode serializes the value to bytes

func (*Value) GetBlob

func (v *Value) GetBlob() []byte

GetBlob returns the value as bytes

func (*Value) GetBool

func (v *Value) GetBool() bool

GetBool returns the value as a boolean

func (*Value) GetDuration

func (v *Value) GetDuration() time.Duration

GetDuration returns the value as time.Duration

func (*Value) GetFloat

func (v *Value) GetFloat() float64

GetFloat returns the value as a float

func (*Value) GetInt

func (v *Value) GetInt() int64

GetInt returns the value as an integer

func (*Value) GetString

func (v *Value) GetString() string

GetString returns the value as a string

func (*Value) GetTime

func (v *Value) GetTime() time.Time

GetTime returns the value as time.Time

func (*Value) IsNull

func (v *Value) IsNull() bool

IsNull returns true if the value is null

Jump to

Keyboard shortcuts

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