db

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: AGPL-3.0 Imports: 6 Imported by: 2

Documentation

Overview

Package db contains a generalized data provider interface aswell as a number of built-in implementations.

Index

Constants

View Source
const (
	// Invalid datatype, must raise error if attempted used.
	DATATYPE_UNKNOWN = 0
	// Bytecode
	DATATYPE_BIN = 1
	// Menu symbol
	DATATYPE_MENU = 2
	// Template symbol
	DATATYPE_TEMPLATE = 4
	// Static LOAD symbols
	DATATYPE_STATICLOAD = 8
	// State and cache from persister
	DATATYPE_STATE = 16
	// Application data
	DATATYPE_USERDATA = 32
)

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

func NewErrNotFound

func NewErrNotFound(k []byte) error

NewErrNotFound creates a new ErrNotFound with the given storage key.

func ToDbKey

func ToDbKey(typ uint8, b []byte, l *lang.Language) []byte

ToDbKey generates a key to use Db to store a value for a particular context.

If language is nil, then default language storage context will be used.

If language is not nil, and the context does not support language, the language value will silently will be ignored.

func ToSessionKey added in v0.2.2

func ToSessionKey(pfx uint8, sessionId []byte, key []byte) []byte

Types

type Db

type Db interface {
	// Connect prepares the storage backend for use.
	//
	// If called more than once, consecutive calls should be ignored.
	Connect(ctx context.Context, connStr string) error
	// Close implements io.Closer.
	//
	// MUST be called before termination after a Connect().
	Close() error
	// Get retrieves the value belonging to a key.
	//
	// Errors if the key does not exist, or if the retrieval otherwise fails.
	Get(ctx context.Context, key []byte) ([]byte, error)
	// Put stores a value under a key.
	//
	// Any existing value will be replaced.
	//
	// Errors if the value could not be stored.
	Put(ctx context.Context, key []byte, val []byte) error
	// SetPrefix sets the storage context prefix to use for consecutive Get and Put operations.
	SetPrefix(pfx uint8)
	// SetSession sets the session context to use for consecutive Get and Put operations.
	//
	// Session only affects the following datatypes:
	// * DATATYPE_STATE
	// * DATATYPE_USERSTART
	SetSession(sessionId string)
	// SetLock disables modification of data that is readonly in the vm context.
	//
	// If called with typ value 0, it will permanently lock all readonly members.
	SetLock(typ uint8, locked bool) error
	// Safe returns true if db is safe for use with a vm.
	Safe() bool
	// SetLanguage sets the language context to use on consecutive gets or puts
	//
	// Language only affects the following datatypes:
	// * DATATYPE_MENU
	// * DATATYPE_TEMPLATE
	// * DATATYPE_STATICLOAD
	SetLanguage(*lang.Language)
	// Prefix returns the current active datatype prefix
	Prefix() uint8
	Dump(context.Context, []byte) (*Dumper, error)
}

Db abstracts all data storage and retrieval as a key-value store

type DbBase

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

DbBase is a base class that must be extended by all db.Db implementers.

It must be created with NewDbBase()

func NewDbBase

func NewDbBase() *DbBase

NewDbBase instantiates a new DbBase.

func (*DbBase) CheckPut

func (bd *DbBase) CheckPut() bool

CheckPut returns true if the current selected data type can be written to.

func (*DbBase) Prefix

func (bd *DbBase) Prefix() uint8

func (*DbBase) Safe

func (bd *DbBase) Safe() bool

func (*DbBase) SetLanguage

func (bd *DbBase) SetLanguage(ln *lang.Language)

SetLanguage implements the Db interface.

func (*DbBase) SetLock

func (bd *DbBase) SetLock(pfx uint8, lock bool) error

SetLock implements the Db interface.

func (*DbBase) SetPrefix

func (bd *DbBase) SetPrefix(pfx uint8)

SetPrefix implements the Db interface.

func (*DbBase) SetSession

func (bd *DbBase) SetSession(sessionId string)

SetSession implements the Db interface.

func (*DbBase) ToKey

func (bd *DbBase) ToKey(ctx context.Context, key []byte) (LookupKey, error)

ToKey creates a DbKey within the current session context.

TODO: hard to read, clean up

type Dumper added in v0.2.2

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

func NewDumper added in v0.2.2

func NewDumper(fn DumperFunc) *Dumper

func (*Dumper) Next added in v0.2.2

func (d *Dumper) Next(ctx context.Context) ([]byte, []byte)

func (*Dumper) WithFirst added in v0.2.2

func (d *Dumper) WithFirst(k []byte, v []byte) *Dumper

type DumperFunc added in v0.2.2

type DumperFunc func(ctx context.Context) ([]byte, []byte)

type ErrNotFound

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

ErrNotFound is returned with a key was successfully queried, but did not match a stored key.

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

Error implements Error.

func (ErrNotFound) Is

func (e ErrNotFound) Is(err error) bool

type LookupKey

type LookupKey struct {
	Default     []byte
	Translation []byte
}

Directories

Path Synopsis
Package dbtest provides test vectors to verify correct operation of a db.Db implementation.
Package dbtest provides test vectors to verify correct operation of a db.Db implementation.
Package fs is a filesystem backed implementation of the db.Db interface.
Package fs is a filesystem backed implementation of the db.Db interface.
Package gdbm is a gdbm database backed implementation of the db.Db interface.
Package gdbm is a gdbm database backed implementation of the db.Db interface.
Package mem is a volatile in-process memory implementation of the db.Db interface.
Package mem is a volatile in-process memory implementation of the db.Db interface.
Package postgres is a Postgres database backed implementation of the db.Db interface.
Package postgres is a Postgres database backed implementation of the db.Db interface.

Jump to

Keyboard shortcuts

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