Documentation ¶
Overview ¶
Package state provides state persistence.
Index ¶
- Constants
- func Funcs[K sys.Kernel, D sys.Device[B], B sys.Button](manager *sys.Manager[K, D, B], log *slog.Logger) rpc.Funcs
- func JSON(db map[rpc.UID]map[string][]byte) ([]byte, error)
- type DB
- func (db *DB) Close() error
- func (db *DB) Delete(owner rpc.UID, item string) error
- func (db *DB) Drop(owner rpc.UID) error
- func (db *DB) DropModule(module string) error
- func (db *DB) Dump() (map[rpc.UID]map[string][]byte, error)
- func (db *DB) DumpModule(module string) (map[rpc.UID]map[string][]byte, error)
- func (db *DB) Get(owner rpc.UID, item string) (val []byte, err error)
- func (db *DB) GetAll(owner rpc.UID) (vals map[string][]byte, err error)
- func (db *DB) Put(owner rpc.UID, item string, new []byte) (old []byte, written bool, err error)
- func (db *DB) Set(owner rpc.UID, item string, val []byte) error
- type DeleteMessage
- type GetMessage
- type GetResult
- type PutMessage
- type PutResult
- type SetMessage
Constants ¶
const Schema = `` /* 170-byte string literal not displayed */
Schema is the DB schema. Module and service columns correspond to rpc.UID.
Variables ¶
This section is empty.
Functions ¶
func Funcs ¶
func Funcs[K sys.Kernel, D sys.Device[B], B sys.Button](manager *sys.Manager[K, D, B], log *slog.Logger) rpc.Funcs
Funcs returns an rpc.Funcs with a function table for accessing a store held by the manager.
The RPC methods in the table are:
- "get": see DB.Get and GetMessage/GetResult
- "set": see DB.Set and SetMessage
- "put": see DB.Put and PutMessage/PutResult
- "delete": DB.Delete and DeleteMessage
- "drop": DB.Drop
- "drop_module": DB.DropModule
"drop" and "drop_module" expect rpc.None as the call message body.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a persistent state store.
func Open ¶
Open opens a DB, creating the tables if required. See https://pkg.go.dev/modernc.org/sqlite#Driver.Open for name handling details.
func (*DB) DropModule ¶
DropModule deletes all entries owned by the module.
func (*DB) DumpModule ¶
DumpModule returns a Go map with all the module's items.
func (*DB) Get ¶
Get returns the owner's named item. Get returns sys.ErrNotFound if no item is found.
type DeleteMessage ¶
type DeleteMessage struct {
Item string `json:"item"`
}
Delete message is the RPC message for deleting an item in the store.
type GetMessage ¶
type GetMessage struct {
Item string `json:"item"`
}
GetMessage is the RPC message for getting a value from the store.
type GetResult ¶
type GetResult struct {
Value []byte `json:"value"`
}
GetResult is the result of a GetMessage RPC call.
type PutMessage ¶
PutMessage is the RPC message for putting a value into the store.
type SetMessage ¶
SetMessage is the RPC message for setting a value into the store.