bdb

package
v0.21.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

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.

View Source
var (
	SystemPath        = []string{"_system"}
	ObjectTypesPath   = []string{"object_types"}
	PermissionsPath   = []string{"permissions"}
	RelationTypesPath = []string{"relation_types"}
	ObjectsPath       = []string{"objects"}
	RelationsSubPath  = []string{"relations_sub"}
	RelationsObjPath  = []string{"relations_obj"}
)

Functions

func BucketExists

func BucketExists(tx *bolt.Tx, path []string) (bool, error)

BucketExists, check if bucket path exists.

func CreateBucket

func CreateBucket(tx *bolt.Tx, path []string) (*bolt.Bucket, error)

CreateBucket, create bucket path if not exists.

func Delete

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

func DeleteBucket

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

DeleteBucket, delete tail bucket of path provided.

func DeleteKey

func DeleteKey(tx *bolt.Tx, path []string, key string) 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 []string, key string) (M, error)

func GetKey

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

GetKey, get key and value from path specified bucket.

func KeyExists

func KeyExists(tx *bolt.Tx, path []string, 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 []string, page *dsc.PaginationRequest) ([]M, *dsc.PaginationResponse, error)

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 []string, filter string) ([]M, error)

func Set

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

func SetBucket

func SetBucket(tx *bolt.Tx, path []string) (*bolt.Bucket, error)

SetBucket, set bucket context to path.

func SetFieldProperty

func SetFieldProperty[T any](target *T, fieldName string, value interface{}) error

func SetKey

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

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

func Unmarshal

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

func UpdateMetadata

func UpdateMetadata[T any, M Message[T]](ctx context.Context, tx *bolt.Tx, path []string, key string, msg *T) (M, 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) Open

func (s *BoltDB) Open() error

Open BoltDB key-value store instance.

type Config

type Config struct {
	DBPath         string
	RequestTimeout time.Duration
}

type DirectoryType

type DirectoryType interface {
	*dsc.Object | *dsc.Relation | *dsc.ObjectType | *dsc.RelationType | *dsc.Permission
	proto.Message
}

type KVIterator

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

KVIterator - key-value iterator.

func NewKVIterator

func NewKVIterator(tx *bolt.Tx, path []string, opts ...KVIteratorOption) (*KVIterator, error)

func (*KVIterator) Error

func (i *KVIterator) Error() error

func (*KVIterator) Key

func (i *KVIterator) Key() []byte

func (*KVIterator) Next

func (i *KVIterator) Next() bool

func (*KVIterator) Value

func (i *KVIterator) Value() []byte

type KVIteratorOption

type KVIteratorOption func(*KVIterator)

func WithPrefix

func WithPrefix(prefix string) KVIteratorOption

type Message

type Message[T any] interface {
	proto.Message
	*T
	GetCreatedAt() *timestamppb.Timestamp
}

Directories

Path Synopsis
mig

Jump to

Keyboard shortcuts

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