Documentation
¶
Index ¶
- Variables
- func BasicTestSuite(provider Provider)
- func BucketTestSuite(provider Provider)
- func Count(ctx context.Context, bucket Bucket) (int64, error)
- func ForEach(ctx context.Context, bucket Bucket, fn func(item Item) error) error
- func IteratorTestSuite(provider Provider)
- func NewResetBucketHandler(db DB, cancel context.CancelFunc) http.Handler
- func NewResetHandler(db DB, cancel context.CancelFunc) http.Handler
- func RelationStoreTestSuite(provider Provider)
- type Bucket
- type BucketName
- type BucketNames
- type DB
- type FuncTx
- type Item
- type Iterator
- type Key
- type Metrics
- type Provider
- type ProviderFunc
- type RelationStore
- type RelationStoreString
- type RelationStoreTx
- type RelationStoreTxString
- type RunnableTx
- type Store
- type StoreAdder
- type StoreAdderTx
- type StoreExists
- type StoreExistsTx
- type StoreGetter
- type StoreGetterTx
- type StoreList
- type StoreListTx
- type StoreMapper
- type StoreMapperTx
- type StoreRemover
- type StoreRemoverTx
- type StoreStream
- type StoreStreamTx
- type StoreTx
- type Tx
Constants ¶
This section is empty.
Variables ¶
var BucketAlreadyExistsError = errors.New("bucket already exists")
BucketAlreadyExistsError is returned when attempting to create a bucket that already exists.
var BucketNotFoundError = errors.New("bucket not found")
BucketNotFoundError is returned when attempting to access a bucket that does not exist.
var KeyNotFoundError = errors.New("key not found")
KeyNotFoundError is currently not return, but can be used as common error
var TransactionAlreadyOpenError = errors.New("transaction already open")
TransactionAlreadyOpenError is returned when attempting to open a transaction while one is already active.
Functions ¶
func BasicTestSuite ¶
func BasicTestSuite(provider Provider)
BasicTestSuite provides a comprehensive test suite for basic database operations that can be reused across different KV implementations.
func BucketTestSuite ¶
func BucketTestSuite(provider Provider)
func Count ¶
Count returns the total number of items in the bucket. Returns -1 if context is cancelled.
func ForEach ¶
ForEach iterates through all items in the bucket and executes the provided function for each item. Iteration stops early if the context is cancelled or if the function returns an error.
func IteratorTestSuite ¶
func IteratorTestSuite(provider Provider)
func NewResetBucketHandler ¶
func NewResetBucketHandler(db DB, cancel context.CancelFunc) http.Handler
NewResetBucketHandler returns a http.Handler that allow delete a bucket
func NewResetHandler ¶
func NewResetHandler(db DB, cancel context.CancelFunc) http.Handler
NewResetHandler returns a http.Handler that allow delete the complete database
func RelationStoreTestSuite ¶
func RelationStoreTestSuite(provider Provider)
Types ¶
type Bucket ¶
type Bucket interface {
Put(ctx context.Context, key []byte, value []byte) error
Get(ctx context.Context, bytes []byte) (Item, error)
Delete(ctx context.Context, bytes []byte) error
Iterator() Iterator
IteratorReverse() Iterator
}
Bucket represents a key-value bucket within a transaction that supports CRUD operations and iteration.
type BucketName ¶
type BucketName []byte
BucketName represents a bucket identifier as a byte slice.
func BucketFromStrings ¶
func BucketFromStrings(values ...string) BucketName
BucketFromStrings creates a bucket name by joining multiple strings with underscores.
func NewBucketName ¶
func NewBucketName(name string) BucketName
NewBucketName creates a new bucket name from a string.
func (BucketName) Bytes ¶
func (b BucketName) Bytes() []byte
Bytes returns the bucket name as a byte slice.
func (BucketName) Equal ¶
func (b BucketName) Equal(value BucketName) bool
Equal compares two bucket names for equality.
func (BucketName) String ¶
func (b BucketName) String() string
String returns the bucket name as a string.
type BucketNames ¶
type BucketNames []BucketName
BucketNames represents a collection of bucket names with utility methods.
func (BucketNames) Contains ¶
func (t BucketNames) Contains(value BucketName) bool
Contains checks if the collection contains the specified bucket name.
type DB ¶
type DB interface {
// Update opens a write transaction
Update(ctx context.Context, fn func(ctx context.Context, tx Tx) error) error
// View opens a read only transaction
View(ctx context.Context, fn func(ctx context.Context, tx Tx) error) error
// Sync database to disk
Sync() error
// Close database
Close() error
// Remove database files from disk
Remove() error
}
DB represents a key-value database that supports transactions and lifecycle management.
func NewDBWithMetrics ¶ added in v1.13.0
NewDBWithMetrics wraps a DB instance with metrics collection for monitoring database operations.
type FuncTx ¶ added in v1.14.0
FuncTx is a function type that implements RunnableTx for executing transaction logic.
type Item ¶
Item represents a key-value pair retrieved from a bucket with existence checking.
func NewByteItem ¶
NewByteItem creates a new Item from raw byte slices for key and value.
type Metrics ¶ added in v1.13.0
type Metrics interface {
DbUpdateInc()
DbViewInc()
}
Metrics provides monitoring capabilities for database operations using Prometheus.
func NewMetrics ¶ added in v1.13.0
func NewMetrics() Metrics
NewMetrics creates a new Metrics instance with default Prometheus counters.
type ProviderFunc ¶
ProviderFunc is a function type that implements the Provider interface.
type RelationStore ¶
type RelationStore[ID ~[]byte | ~string, RelatedID ~[]byte | ~string] interface { // Add the given relationIDs to ID Add(ctx context.Context, id ID, relatedIds []RelatedID) error // Replace all relations of id with the given Replace(ctx context.Context, id ID, relatedIds []RelatedID) error // Remove all relation from ID to the given Remove(ctx context.Context, id ID, relatedIds []RelatedID) error // Delete ID and all relations Delete(ctx context.Context, id ID) error // RelatedIDs return all relation of ID RelatedIDs(ctx context.Context, id ID) ([]RelatedID, error) // IDs return all ids of RelatedID IDs(ctx context.Context, relatedId RelatedID) ([]ID, error) // StreamIDs return all existing IDs StreamIDs(ctx context.Context, ch chan<- ID) error // StreamRelatedIDs return all existing relationIDs StreamRelatedIDs(ctx context.Context, ch chan<- RelatedID) error // MapIDRelations maps all entry to the given func MapIDRelations( ctx context.Context, fn func(ctx context.Context, key ID, relatedIDs []RelatedID) error, ) error // MapRelationIDs maps all entry to the given func MapRelationIDs( ctx context.Context, fn func(ctx context.Context, key RelatedID, ids []ID) error, ) error // Invert returns the same store with flipped ID <-> RelationID Invert() RelationStore[RelatedID, ID] }
RelationStore implement a forward and backword id lookup for a 1:N relation.
func NewRelationStore ¶
func NewRelationStoreFromRelationStoreTx ¶ added in v1.12.0
func NewRelationStoreFromRelationStoreTx[ID ~[]byte | ~string, RelatedID ~[]byte | ~string]( db DB, storeTx RelationStoreTx[ID, RelatedID], ) RelationStore[ID, RelatedID]
type RelationStoreString ¶
type RelationStoreString RelationStore[string, string]
type RelationStoreTx ¶
type RelationStoreTx[ID ~[]byte | ~string, RelatedID ~[]byte | ~string] interface { // Add the given relationIDs to ID Add(ctx context.Context, tx Tx, id ID, relatedIds []RelatedID) error // Replace all relations of id with the given Replace(ctx context.Context, tx Tx, id ID, relatedIds []RelatedID) error // Remove all relation from ID to the given Remove(ctx context.Context, tx Tx, id ID, relatedIds []RelatedID) error // Delete ID and all relations Delete(ctx context.Context, tx Tx, id ID) error // RelatedIDs return all relation of ID RelatedIDs(ctx context.Context, tx Tx, id ID) ([]RelatedID, error) // IDs return all ids of RelatedID IDs(ctx context.Context, tx Tx, relatedId RelatedID) ([]ID, error) // StreamIDs return all existing IDs StreamIDs(ctx context.Context, tx Tx, ch chan<- ID) error // StreamRelatedIDs return all existing relationIDs StreamRelatedIDs(ctx context.Context, tx Tx, ch chan<- RelatedID) error // Invert returns the same store with flipped ID <-> RelationID Invert() RelationStoreTx[RelatedID, ID] // MapIDRelations maps all entry to the given func MapIDRelations( ctx context.Context, tx Tx, fn func(ctx context.Context, key ID, relatedIDs []RelatedID) error, ) error // MapRelationIDs maps all entry to the given func MapRelationIDs( ctx context.Context, tx Tx, fn func(ctx context.Context, key RelatedID, ids []ID) error, ) error }
func NewRelationStoreTx ¶
func NewRelationStoreTxWithBucket ¶ added in v1.12.0
type RelationStoreTxString ¶
type RelationStoreTxString RelationStoreTx[string, string]
type RunnableTx ¶ added in v1.14.0
RunnableTx provides an interface for executing transaction logic.
type Store ¶
type Store[KEY ~[]byte | ~string, OBJECT any] interface { StoreAdder[KEY, OBJECT] StoreRemover[KEY] StoreGetter[KEY, OBJECT] StoreMapper[KEY, OBJECT] StoreExists[KEY, OBJECT] StoreStream[KEY, OBJECT] StoreList[KEY, OBJECT] }
Store provides a complete type-safe key-value store interface combining all store operations.
type StoreAdder ¶
type StoreAdder[KEY ~[]byte | ~string, OBJECT any] interface { Add(ctx context.Context, key KEY, object OBJECT) error }
StoreAdder provides functionality to add objects to a store.
type StoreAdderTx ¶
type StoreAdderTx[KEY ~[]byte | ~string, OBJECT any] interface { Add(ctx context.Context, tx Tx, key KEY, object OBJECT) error }
StoreAdderTx provides functionality to add objects within a transaction.
type StoreExists ¶
type StoreExists[KEY ~[]byte | ~string, OBJECT any] interface { Exists(ctx context.Context, key KEY) (bool, error) }
StoreExists provides functionality to check object existence in a store.
type StoreExistsTx ¶
type StoreExistsTx[KEY ~[]byte | ~string, OBJECT any] interface { Exists(ctx context.Context, tx Tx, key KEY) (bool, error) }
StoreExistsTx provides functionality to check object existence within a transaction.
type StoreGetter ¶
type StoreGetter[KEY ~[]byte | ~string, OBJECT any] interface { Get(ctx context.Context, key KEY) (*OBJECT, error) }
StoreGetter provides functionality to retrieve objects from a store.
type StoreGetterTx ¶
type StoreGetterTx[KEY ~[]byte | ~string, OBJECT any] interface { Get(ctx context.Context, tx Tx, key KEY) (*OBJECT, error) }
StoreGetterTx provides functionality to retrieve objects within a transaction.
type StoreList ¶ added in v1.15.0
type StoreList[KEY ~[]byte | ~string, OBJECT any] interface { List(ctx context.Context) ([]OBJECT, error) }
StoreList provides functionality to list all objects from a store.
type StoreListTx ¶ added in v1.15.0
type StoreListTx[KEY ~[]byte | ~string, OBJECT any] interface { List(ctx context.Context, tx Tx) ([]OBJECT, error) }
StoreListTx provides functionality to list all objects within a transaction.
type StoreMapper ¶
type StoreMapper[KEY ~[]byte | ~string, OBJECT any] interface { Map(ctx context.Context, fn func(ctx context.Context, key KEY, object OBJECT) error) error }
StoreMapper provides mapping functionality over all key-value pairs in a store.
type StoreMapperTx ¶
type StoreMapperTx[KEY ~[]byte | ~string, OBJECT any] interface { Map( ctx context.Context, tx Tx, fn func(ctx context.Context, key KEY, object OBJECT) error, ) error }
StoreMapperTx provides mapping functionality over all key-value pairs within a transaction.
type StoreRemover ¶
StoreRemover provides functionality to remove objects from a store.
type StoreRemoverTx ¶
type StoreRemoverTx[KEY ~[]byte | ~string] interface { Remove(ctx context.Context, tx Tx, key KEY) error }
StoreRemoverTx provides functionality to remove objects within a transaction.
type StoreStream ¶
type StoreStream[KEY ~[]byte | ~string, OBJECT any] interface { Stream(ctx context.Context, ch chan<- OBJECT) error }
StoreStream provides functionality to stream all objects from a store.
type StoreStreamTx ¶
type StoreStreamTx[KEY ~[]byte | ~string, OBJECT any] interface { Stream(ctx context.Context, tx Tx, ch chan<- OBJECT) error }
StoreStreamTx provides functionality to stream all objects within a transaction.
type StoreTx ¶
type StoreTx[KEY ~[]byte | ~string, OBJECT any] interface { StoreAdderTx[KEY, OBJECT] StoreRemoverTx[KEY] StoreGetterTx[KEY, OBJECT] StoreMapperTx[KEY, OBJECT] StoreExistsTx[KEY, OBJECT] StoreStreamTx[KEY, OBJECT] StoreListTx[KEY, OBJECT] }
StoreTx provides a complete type-safe key-value store interface for transaction-based operations.
func NewStoreTx ¶
func NewStoreTx[KEY ~[]byte | ~string, OBJECT any](bucketName BucketName) StoreTx[KEY, OBJECT]
NewStoreTx creates a new type-safe transaction-based store for the specified bucket.
type Tx ¶
type Tx interface {
Bucket(ctx context.Context, name BucketName) (Bucket, error)
CreateBucket(ctx context.Context, name BucketName) (Bucket, error)
CreateBucketIfNotExists(ctx context.Context, name BucketName) (Bucket, error)
DeleteBucket(ctx context.Context, name BucketName) error
ListBucketNames(ctx context.Context) (BucketNames, error)
}
Tx represents a database transaction that provides bucket management operations.
Source Files
¶
- kv_basic-test-suite.go
- kv_bucket-name.go
- kv_bucket-test-suite.go
- kv_bucket.go
- kv_count.go
- kv_db-metrics.go
- kv_db.go
- kv_foreach.go
- kv_item.go
- kv_iterator-test-suite.go
- kv_iterator.go
- kv_key.go
- kv_metrics.go
- kv_provider.go
- kv_relation-store-tx.go
- kv_relation-store.go
- kv_relation-store_test-suite.go
- kv_reset-bucket-handler.go
- kv_reset-db-handler.go
- kv_run-func.go
- kv_store-tx.go
- kv_store.go
- kv_tx.go