store

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MemoryType = "memory"
	BoltType   = "bolt"
)

Variables

View Source
var ErrNotFound = errors.New("store: key not found")

Get never returns (nil, nil)

Functions

This section is empty.

Types

type BoltStore

type BoltStore[T any] struct {
	Db       *bolt.DB
	DbFile   string
	FileMode os.FileMode
	Bucket   string
	// contains filtered or unexported fields
}

BoltStore is a generic bbolt-backed implementation of Store[T] Values are json-marshalled into a single bucket, keyed by the 16 raw bytes of the value's uuid. In short, key: uuid.UUID; value: T

func Bucket

func Bucket[T any](s *SharedBolt, bucket string) (*BoltStore[T], error)

func NewBoltStore

func NewBoltStore[T any](file string, mode os.FileMode, bucket string) (*BoltStore[T], error)

func (*BoltStore[T]) Close

func (s *BoltStore[T]) Close() error

func (*BoltStore[T]) Count

func (s *BoltStore[T]) Count() (int, error)

func (*BoltStore[T]) CreateBucket

func (s *BoltStore[T]) CreateBucket() error

func (*BoltStore[T]) Delete

func (s *BoltStore[T]) Delete(key uuid.UUID) error

func (*BoltStore[T]) Get

func (s *BoltStore[T]) Get(key uuid.UUID) (*T, error)

func (*BoltStore[T]) List

func (s *BoltStore[T]) List() ([]*T, error)

func (*BoltStore[T]) Put

func (s *BoltStore[T]) Put(key uuid.UUID, value *T) error

type InMemoryStore

type InMemoryStore[T Keyable] struct {
	// contains filtered or unexported fields
}

func NewInMemoryStore

func NewInMemoryStore[T Keyable]() *InMemoryStore[T]

func (*InMemoryStore[T]) Close

func (i *InMemoryStore[T]) Close() error

func (*InMemoryStore[T]) Count

func (i *InMemoryStore[T]) Count() (int, error)

func (*InMemoryStore[T]) Delete

func (i *InMemoryStore[T]) Delete(key uuid.UUID) error

func (*InMemoryStore[T]) Get

func (i *InMemoryStore[T]) Get(key uuid.UUID) (*T, error)

func (*InMemoryStore[T]) List

func (i *InMemoryStore[T]) List() ([]*T, error)

func (*InMemoryStore[T]) Put

func (i *InMemoryStore[T]) Put(key uuid.UUID, value *T) error

type Keyable

type Keyable interface {
	Key() uuid.UUID
}

need this for List to be deterministic since i sort the slice by the key

type SharedBolt

type SharedBolt struct {
	Db     *bolt.DB
	DbFile string
}

owns a single bbolt file backing several bucket views. bbolt takes an exclusive lock on the file, so a component's stores must all come from one open handle. SharedBolt acts as that handle, and Bucket hands out Store[T] views over its buckets

func OpenSharedBolt

func OpenSharedBolt(file string, mode os.FileMode) (*SharedBolt, error)

func (*SharedBolt) Close

func (s *SharedBolt) Close() error

type Store

type Store[T any] interface {
	Put(key uuid.UUID, value *T) error
	Get(key uuid.UUID) (*T, error)
	List() ([]*T, error)
	Count() (int, error)
	Delete(key uuid.UUID) error
	Close() error
}

Jump to

Keyboard shortcuts

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