bdb

package
v0.33.1 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ManifestName    string = "default"
	ManifestVersion string = "0.0.1"
)

Variables

View Source
var (
	ErrPathNotFound    = cerr.NewAsertoError("E20050", codes.NotFound, http.StatusNotFound, "path not found")
	ErrKeyNotFound     = cerr.NewAsertoError("E20051", codes.NotFound, http.StatusNotFound, "key not found")
	ErrKeyExists       = cerr.NewAsertoError("E20052", codes.AlreadyExists, http.StatusConflict, "key already exists")
	ErrMultipleResults = cerr.NewAsertoError("E20053", codes.FailedPrecondition, http.StatusExpectationFailed, "multiple results for singleton request")
)

Error codes returned by failures to parse an expression.

Functions

func BucketExists

func BucketExists(tx *bolt.Tx, path Path) (bool, error)

BucketExists, check if bucket path exists.

func CreateBucket

func CreateBucket(tx *bolt.Tx, path Path) (*bolt.Bucket, error)

CreateBucket, create bucket path if not exists.

func Delete

func Delete(ctx context.Context, tx *bolt.Tx, path Path, key []byte) error

func DeleteBucket

func DeleteBucket(tx *bolt.Tx, path Path) error

DeleteBucket, delete tail bucket of path provided.

func DeleteKey

func DeleteKey(tx *bolt.Tx, path Path, key []byte) error

DeleteKey, delete key and value in path specified bucket, when it exists. None existing keys will not raise an error.

func Get

func Get[T any, M Message[T]](ctx context.Context, tx *bolt.Tx, path Path, key []byte) (M, error)

func GetAny added in v0.30.0

func GetAny[T any](ctx context.Context, tx *bolt.Tx, path Path, key []byte) (*T, error)

func GetKey

func GetKey(tx *bolt.Tx, path Path, key []byte) ([]byte, error)

GetKey, get key and value from path specified bucket.

func KeyExists

func KeyExists(tx *bolt.Tx, path Path, key []byte) (bool, error)

KeyExists, check if the key exists in the path specified bucket.

func KeyPrefixExists added in v0.33.1

func KeyPrefixExists[T any, M Message[T]](ctx context.Context, tx *bolt.Tx, path Path, keyFilter []byte) (bool, error)

func List

func List[T any, M Message[T]](ctx context.Context, tx *bolt.Tx, path Path) ([]M, error)

func ListBuckets added in v0.30.0

func ListBuckets(tx *bolt.Tx, path Path) ([]string, error)

ListBuckets, returns the bucket name underneath the path.

func Scan

func Scan[T any, M Message[T]](ctx context.Context, tx *bolt.Tx, path Path, keyFilter []byte) ([]M, error)

func ScanWithFilter added in v0.33.1

func ScanWithFilter(
	ctx context.Context,
	tx *bolt.Tx,
	path Path,
	keyFilter []byte,
	valueFilter func(*dsc3.RelationIdentifier) bool,
	pool graph.RelationPool,
	out *[]*dsc3.RelationIdentifier,
) error

func Set

func Set[T any, M Message[T]](ctx context.Context, tx *bolt.Tx, path Path, key []byte, t M) (M, error)

func SetAny added in v0.30.0

func SetAny[T any](ctx context.Context, tx *bolt.Tx, path Path, key []byte, t *T) (*T, error)

func SetBucket

func SetBucket(tx *bolt.Tx, path Path) (*bolt.Bucket, error)

SetBucket, set bucket context to path.

func SetKey

func SetKey(tx *bolt.Tx, path Path, key, value []byte) error

SetKey, set key and value in the path specified bucket.

Types

type BoltDB

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

BoltDB based key-value store.

func New

func New(config *Config, logger *zerolog.Logger) (*BoltDB, error)

func (*BoltDB) Close

func (s *BoltDB) Close()

Close closes BoltDB key-value store instance.

func (*BoltDB) Config

func (s *BoltDB) Config() *Config

func (*BoltDB) DB

func (s *BoltDB) DB() *bolt.DB

func (*BoltDB) LoadModel added in v0.30.0

func (s *BoltDB) LoadModel() error

LoadModel, reads the serialized model from the store and swaps the model instance in the cache.Cache using cache.UpdateModel.

func (*BoltDB) MC added in v0.30.0

func (s *BoltDB) MC() *cache.Cache

MC, model cache.

func (*BoltDB) Open

func (s *BoltDB) Open() error

Open BoltDB key-value store instance.

type Config

type Config struct {
	DBPath         string
	RequestTimeout time.Duration
	MaxBatchSize   int
	MaxBatchDelay  time.Duration
}

type Iterator added in v0.21.5

type Iterator[T any, M Message[T]] interface {
	Next() bool       // move cursor to next element.
	RawKey() []byte   // return raw key value ([]byte).
	RawValue() []byte // return ram value value ([]byte).
	Key() string      // return key value (string).
	Value() M         // return typed value (M).
	Delete() error    // delete element underneath cursor.
}

func NewScanIterator added in v0.21.5

func NewScanIterator[T any, M Message[T]](ctx context.Context, tx *bolt.Tx, path Path, opts ...ScanOption) (Iterator[T, M], error)

type Message

type Message[T any] interface {
	proto.Message
	UnmarshalVT([]byte) error
	*T
}

type PageIterator added in v0.21.5

type PageIterator[T any, M Message[T]] struct {
	// contains filtered or unexported fields
}

func (*PageIterator[T, M]) Next added in v0.21.5

func (p *PageIterator[T, M]) Next() bool

func (*PageIterator[T, M]) NextToken added in v0.21.5

func (p *PageIterator[T, M]) NextToken() string

func (*PageIterator[T, M]) Value added in v0.21.5

func (p *PageIterator[T, M]) Value() []M

type PagedIterator added in v0.21.5

type PagedIterator[T any, M Message[T]] interface {
	Next() bool
	Value() []M
	NextToken() string
}

func NewPageIterator added in v0.21.5

func NewPageIterator[T any, M Message[T]](ctx context.Context, tx *bolt.Tx, path Path, opts ...ScanOption) (PagedIterator[T, M], error)

type Path added in v0.21.5

type Path []string
var (
	SystemPath        Path = []string{"_system"}
	ManifestPath      Path = []string{"_manifest", ManifestName, ManifestVersion}
	ObjectTypesPath   Path = []string{"object_types"}
	PermissionsPath   Path = []string{"permissions"}
	RelationTypesPath Path = []string{"relation_types"}
	ObjectsPath       Path = []string{"objects"}
	RelationsSubPath  Path = []string{"relations_sub"}
	RelationsObjPath  Path = []string{"relations_obj"}
	MetadataKey            = []byte("metadata")
	BodyKey                = []byte("body")
	ModelKey               = []byte("model")
)

type ScanArgs added in v0.21.5

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

type ScanIterator added in v0.21.5

type ScanIterator[T any, M Message[T]] struct {
	// contains filtered or unexported fields
}

func (*ScanIterator[T, M]) Delete added in v0.21.5

func (s *ScanIterator[T, M]) Delete() error

func (*ScanIterator[T, M]) Key added in v0.21.5

func (s *ScanIterator[T, M]) Key() string

func (*ScanIterator[T, M]) Next added in v0.21.5

func (s *ScanIterator[T, M]) Next() bool

func (*ScanIterator[T, M]) RawKey added in v0.21.5

func (s *ScanIterator[T, M]) RawKey() []byte

func (*ScanIterator[T, M]) RawValue added in v0.21.5

func (s *ScanIterator[T, M]) RawValue() []byte

func (*ScanIterator[T, M]) Value added in v0.21.5

func (s *ScanIterator[T, M]) Value() M

type ScanOption added in v0.21.5

type ScanOption func(*ScanArgs)

func WithKeyFilter added in v0.21.5

func WithKeyFilter(filter []byte) ScanOption

func WithPageSize added in v0.21.5

func WithPageSize(size int32) ScanOption

func WithPageToken added in v0.21.5

func WithPageToken(token string) ScanOption

Directories

Path Synopsis
mig

Jump to

Keyboard shortcuts

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