vbolt

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: MIT Imports: 14 Imported by: 1

README

vBolt is a low latency database layer with an exclusively programmatic interface and explicit-only indexing

See https://judi.systems/vbolt

Documentation

Index

Constants

View Source
const BUCKET_HEADER byte = 0x01
View Source
const CCountPrefix byte = 0x13
View Source
const CItemPrefix byte = 0x12
View Source
const CKeyPrefix byte = 0x10
View Source
const ITEM_HEADER byte = 0x02
View Source
const IndexCountPrefix byte = 0x03
View Source
const IndexTargetPrefix byte = 0x02
View Source
const IndexTermPrefix byte = 0x01
View Source
const IterateRegular = IterationDirection(0)
View Source
const IterateReverse = IterationDirection(1)

Variables

View Source
var DBProcesses = Bucket(&dbInfo, "proc", vpack.StringZ, vpack.UnixTime)
View Source
var PackCountFn = vpack.Int

Functions

func ApplyDBProcess

func ApplyDBProcess(db *DB, name string, processFn func())

kind of like a migration, but mostly we expect it to be about recreating indecies and stuff

func BackupBuckets

func BackupBuckets(db *DB, out *bufio.Writer, bucketNames ...string) error

func ChannelError

func ChannelError(target *error, err error)

func CollectionAddEntry added in v0.2.0

func CollectionAddEntry[K, O, I any](tx *Tx, info *CollectionInfo[K, O, I], key K, order O, item I)

func CollectionRemoveEntry added in v0.2.0

func CollectionRemoveEntry[K, O, I any](tx *Tx, info *CollectionInfo[K, O, I], key K, item I)

func DEBUGInspect

func DEBUGInspect[K, V any](tx *Tx, bucket *BucketInfo[K, V])

func Delete

func Delete[K, T any](tx *Tx, info *BucketInfo[K, T], id K)

func DeleteTargetTerms

func DeleteTargetTerms[K, T, P comparable](tx *Tx, indexInfo *IndexInfo[K, T, P], target K)

func DumpBucketJSON

func DumpBucketJSON[K, V any](db *DB, out *bufio.Writer, label string, bucket *BucketInfo[K, V])

func EnsureBuckets

func EnsureBuckets(tx *Tx, dbInfo *Info)

func GenericRead

func GenericRead(tx *Tx, inspection *Inspection)

GenericRead takes a generic bucketInfo (must be *BucketInfo, i.e. a pointer) and reads a list of keys and values without really knowing the underlying type. Introspection is needed to properly display the type. Formatting the data as JSON is a good start.

func HasKey

func HasKey[K, T any](tx *Tx, bucketInfo *BucketInfo[K, T], id K) bool

func InitBuckets added in v0.2.3

func InitBuckets(db *DB, infos ...*Info)

func IterateAll

func IterateAll[K, T any](tx *Tx, bucketInfo *BucketInfo[K, T], visitFn func(key K, item T) bool)

func IterateAllReverse

func IterateAllReverse[K, T any](tx *Tx, bucketInfo *BucketInfo[K, T], visitFn func(key K, item T) bool)

func IterateAllTerms

func IterateAllTerms[K, T, P comparable](tx *Tx, indexInfo *IndexInfo[K, T, P], visitFn func(term T, target K, priority P) bool)

func IterateBucketFrom added in v0.2.0

func IterateBucketFrom[K, T any](tx *Tx, bucketInfo *BucketInfo[K, T], startKey K, visitFn func(key K, value T) bool) []byte

IterateBucketFrom lets you specify the starting key using the userspace key type

func IterateBucketFromPartial added in v0.2.4

func IterateBucketFromPartial[K, T any](tx *Tx, bucketInfo *BucketInfo[K, T], startKey K, visitFn func(key K, value T) bool) []byte

IterateBucketFromPartial lets you specify the starting key using the userspace key type and lets you fill it partially

func IterateCollection added in v0.2.0

func IterateCollection[K, O, I any](tx *Tx, info *CollectionInfo[K, O, I], key K, visit func(key K, order O, item I) bool)

func IterateCollectionReverse added in v0.2.0

func IterateCollectionReverse[K, O, I any](tx *Tx, info *CollectionInfo[K, O, I], key K, visit func(key K, order O, item I) bool)

func IterateInBatches

func IterateInBatches[K, T any](tx *Tx, bucketInfo *BucketInfo[K, T], batchSize int, visitFn func(items []T) bool)

func IterateTarget

func IterateTarget[K, T, P comparable](tx *Tx, indexInfo *IndexInfo[K, T, P], target K, visitFn func(term T, priority P) bool)

iterate over terms that are assigned to target

func IterateTerm

func IterateTerm[K, T, P comparable](tx *Tx, indexInfo *IndexInfo[K, T, P], term T, visitFn func(target K, priority P) bool) []byte

func NextIntId

func NextIntId[K, T any](tx *Tx, info *BucketInfo[K, T]) int

func RawHasKey

func RawHasKey(bkt *BBucket, key []byte) bool

func RawMustPut

func RawMustPut(bkt *BBucket, key []byte, value []byte)

Put an entry

func RawNextSequence

func RawNextSequence(bucket *BBucket) uint64

func RawSetSequenceCorrectly

func RawSetSequenceCorrectly(bucket *BBucket)

func Read

func Read[K comparable, T any](tx *Tx, bucketInfo *BucketInfo[K, T], id K, item *T) bool

func ReadAppend

func ReadAppend[K comparable, T any](tx *Tx, bucketInfo *BucketInfo[K, T], id K, list *[]T) bool

like read slice but for reading one item and appending it to a list

func ReadCollection added in v0.2.0

func ReadCollection[K, O, I any](tx *Tx, info *CollectionInfo[K, O, I], key K, items *[]I, count int)

func ReadCollectionReverse added in v0.2.0

func ReadCollectionReverse[K, O, I any](tx *Tx, info *CollectionInfo[K, O, I], key K, items *[]I, count int)

func ReadSlice

func ReadSlice[K comparable, T any](tx *Tx, bucketInfo *BucketInfo[K, T], ids []K, list *[]T) int

ReadSlice reads objects given by ids, appending them to the given slice. returns the number of objects that were successfully read

func ReadSliceToMap

func ReadSliceToMap[K comparable, T any](tx *Tx, bucketInfo *BucketInfo[K, T], ids []K, itemsMap map[K]T) int

ReadSliceToMap reads objects given by id into the given map. returns the number of objects that were successfully read

func ReadTermCount

func ReadTermCount[K, T, P comparable](tx *Tx, indexInfo *IndexInfo[K, T, P], term *T, count *int) bool

func ReadTermTargetSingle

func ReadTermTargetSingle[K, T, P comparable](tx *Tx, indexInfo *IndexInfo[K, T, P], term T, target *K) bool

func ReadTermTargets

func ReadTermTargets[K, T, P comparable](tx *Tx, indexInfo *IndexInfo[K, T, P], term T, targets *[]K, window Window) []byte

func ReadToMap

func ReadToMap[K comparable, T any](tx *Tx, bucketInfo *BucketInfo[K, T], id K, itemsMap map[K]T) bool

func RestoreBuckets

func RestoreBuckets(db *DB, in *bytes.Reader) error

func RunProcess

func RunProcess(label string, processFn func())

func ScanList

func ScanList[K, T any](tx *Tx, bucketInfo *BucketInfo[K, T], startKey K, count int, items *[]T) (nextKey K, done bool)

func SetTargetSingleTerm

func SetTargetSingleTerm[K, T, P comparable](tx *Tx, indexInfo *IndexInfo[K, T, P], target K, term T)

func SetTargetSingleTermExt added in v0.2.0

func SetTargetSingleTermExt[K, T, P comparable](tx *Tx, indexInfo *IndexInfo[K, T, P], target K, priority P, term T)

func SetTargetTerms

func SetTargetTerms[K, T, P comparable](tx *Tx, indexInfo *IndexInfo[K, T, P], target K, terms map[T]P)

Updates target,term pairs so that only the terms provided here point to target. terms map the term to the priority

func SetTargetTermsPlain

func SetTargetTermsPlain[K, T, P comparable](tx *Tx, indexInfo *IndexInfo[K, T, P], target K, terms []T)

sets terms without priorities

func SetTargetTermsUniform

func SetTargetTermsUniform[K, T, P comparable](tx *Tx, indexInfo *IndexInfo[K, T, P], target K, terms []T, priority P)

func TxClose

func TxClose(tx *Tx)

func TxCommit added in v0.1.2

func TxCommit(tx *Tx)

func TxWriteBatches

func TxWriteBatches[Key, Struct any](db *DB, info *BucketInfo[Key, Struct], batchSize int, processFn func(tx *Tx, batch []Struct))

func UniformTerms

func UniformTerms[T, P comparable](terms []T, priority P) (out map[T]P)

func WarmTheCache

func WarmTheCache(tx *Tx, dbInfo *Info)

Some helpers that most apps will need

func WithReadTx added in v0.2.0

func WithReadTx(db *DB, fn func(tx *Tx))

func WithWriteTx

func WithWriteTx(db *DB, fn func(tx *Tx))

WithWriteTx calls supplied function with a writeable transaction

Caller must commit the tx explicitly; otherwise it will get rolled back by default

func Write

func Write[K comparable, T any](tx *Tx, bucketInfo *BucketInfo[K, T], id K, item *T)

Writes an item to a key. Note: does not write anything if id is the zero value

Types

type BBucket

type BBucket = bolt.Bucket

func TxRawBucket

func TxRawBucket(tx *Tx, name string) *BBucket

type BucketInfo

type BucketInfo[K, T any] struct {
	Name        string
	KeyPackFn   vpack.PackFn[K]
	ValuePackFn vpack.PackFn[T]
}

func Bucket

func Bucket[K, T any](dbInfo *Info, name string, keyFn vpack.PackFn[K], serFn vpack.PackFn[T]) *BucketInfo[K, T]

type CollectionInfo added in v0.2.0

type CollectionInfo[K, O, I any] struct {
	Name string

	KeyFn   vpack.PackFn[K]
	OrderFn vpack.PackFn[O]
	ItemFn  vpack.PackFn[I]
}

collection bucket

func Collection added in v0.2.0

func Collection[K, O, I any](dbInfo *Info, name string, keyFn vpack.PackFn[K], orderFn vpack.PackFn[O], itemFn vpack.PackFn[I]) *CollectionInfo[K, O, I]

type Cursor

type Cursor = bolt.Cursor

type DB

type DB = bolt.DB

func Open

func Open(filename string) *DB

type GenericItem

type GenericItem struct {
	Key   any
	Value any
}

type IndexInfo

type IndexInfo[K, T, P comparable] struct {
	Name           string
	TargetPackFn   vpack.PackFn[K]
	TermPackFn     vpack.PackFn[T]
	PriorityPackFn vpack.PackFn[P]
}

func Index

func Index[K, T comparable](dbInfo *Info, name string, termFn vpack.PackFn[T], targetFn vpack.PackFn[K]) *IndexInfo[K, T, uint16]

func IndexExt added in v0.2.0

func IndexExt[K, T, P comparable](dbInfo *Info, name string, termFn vpack.PackFn[T], priorityFn vpack.PackFn[P], targetFn vpack.PackFn[K]) *IndexInfo[K, T, P]

type Info

type Info struct {
	BucketList     []string
	IndexList      []string
	CollectionList []string

	Infos map[string]any
}

type Inspection

type Inspection struct {
	// request
	BucketInfoPtr any // must be a *BucketInfo[K, V]
	Limit         int

	// both request/response
	NextKey any

	// response
	Items           []GenericItem
	TotalItemsCount int
}

type InspectionBucketMetadata added in v0.2.4

type InspectionBucketMetadata struct {
	Name        string
	KeyPackFn   reflect.Value
	ValuePackFn reflect.Value

	KeyType   reflect.Type
	ValueType reflect.Type
}

func InspectAnyBucketInfo added in v0.2.4

func InspectAnyBucketInfo(bucketInfo any) (meta InspectionBucketMetadata)

type IterationDirection added in v0.2.1

type IterationDirection uint8

type Tx

type Tx = bolt.Tx

func ReadTx added in v0.2.0

func ReadTx(db *DB) *Tx

func WriteTx

func WriteTx(db *DB) *Tx

type Window

type Window struct {
	Limit     int // 0 means unlimited
	Offset    int // if both offset and cursor are set, cursor is used
	Cursor    []byte
	Direction IterationDirection
}

Jump to

Keyboard shortcuts

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