Documentation ¶
Overview ¶
Package db contains a generalized data provider interface aswell as a number of built-in implementations.
Index ¶
- Constants
- func IsNotFound(err error) bool
- func NewErrNotFound(k []byte) error
- func ToDbKey(typ uint8, b []byte, l *lang.Language) []byte
- func ToSessionKey(pfx uint8, sessionId []byte, key []byte) []byte
- type Db
- type DbBase
- func (bd *DbBase) CheckPut() bool
- func (bd *DbBase) Prefix() uint8
- func (bd *DbBase) Safe() bool
- func (bd *DbBase) SetLanguage(ln *lang.Language)
- func (bd *DbBase) SetLock(pfx uint8, lock bool) error
- func (bd *DbBase) SetPrefix(pfx uint8)
- func (bd *DbBase) SetSession(sessionId string)
- func (bd *DbBase) ToKey(ctx context.Context, key []byte) (LookupKey, error)
- type Dumper
- type DumperFunc
- type ErrNotFound
- type LookupKey
Constants ¶
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 NewErrNotFound ¶
NewErrNotFound creates a new ErrNotFound with the given storage key.
func ToDbKey ¶
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.
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 (*DbBase) CheckPut ¶
CheckPut returns true if the current selected data type can be written to.
func (*DbBase) SetLanguage ¶
SetLanguage implements the Db interface.
func (*DbBase) SetLock ¶
SetLock implements the Db interface.
func (*DbBase) SetPrefix ¶
SetPrefix implements the Db interface.
func (*DbBase) SetSession ¶
SetSession implements the Db interface.
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
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) Is ¶
func (e ErrNotFound) Is(err error) bool
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. |