bdb

package
v0.31.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ManifestName    string = "default"
	ManifestVersion string = "0.0.1"
	MetadataKey     string = "metadata"
	BodyKey         string = "body"
	ModelKey        string = "model"
)

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 string) 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 string) error

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

func ErrIsNotFound added in v0.30.0

func ErrIsNotFound(err error) bool

func Get

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

func GetAny added in v0.30.0

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

func GetKey

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

GetKey, get key and value from path specified bucket.

func GetObject added in v0.31.4

func GetObject(ctx context.Context, tx *bolt.Tx, path Path, key string) (*dsc3.Object, error)

func GetRelation added in v0.31.4

func GetRelation(ctx context.Context, tx *bolt.Tx, path Path, key string) (*dsc3.Relation, error)

func KeyExists

func KeyExists(tx *bolt.Tx, path Path, key string) (bool, error)

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

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 Marshal

func Marshal[T any, M Message[T]](t M) ([]byte, error)

func Scan

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

func Set

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

func SetAny added in v0.30.0

func SetAny[T any](ctx context.Context, tx *bolt.Tx, path Path, key string, 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 string, value []byte) error

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

func SetObject added in v0.31.4

func SetObject(ctx context.Context, tx *bolt.Tx, path Path, key string, obj *dsc3.Object) (*dsc3.Object, error)

func SetRelation added in v0.31.4

func SetRelation(ctx context.Context, tx *bolt.Tx, path Path, key string, rel *dsc3.Relation) (*dsc3.Relation, error)

func Unmarshal

func Unmarshal[T any, M Message[T]](b []byte) (M, error)

func UpdateMetadataObject added in v0.31.4

func UpdateMetadataObject(ctx context.Context, tx *bolt.Tx, path []string, key string, msg *dsc3.Object) (*dsc3.Object, error)

func UpdateMetadataRelation added in v0.31.4

func UpdateMetadataRelation(ctx context.Context, tx *bolt.Tx, path []string, key string, msg *dsc3.Relation) (*dsc3.Relation, error)

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
	*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"}
)

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]) SetFilter added in v0.21.5

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

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 string) 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