state

package
v0.0.0-...-d368998 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package state provides state persistence.

Index

Constants

View Source
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:

"drop" and "drop_module" expect rpc.None as the call message body.

func JSON

func JSON(db map[rpc.UID]map[string][]byte) ([]byte, error)

JSON returns a JSON representation of a DB map dump returned by Dump or DumpModule.

Types

type DB

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

DB is a persistent state store.

func Open

func Open(name string, log *slog.Logger) (*DB, error)

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

func (db *DB) Close() error

Close closes the database.

func (*DB) Delete

func (db *DB) Delete(owner rpc.UID, item string) error

Delete removes the owner's named item.

func (*DB) Drop

func (db *DB) Drop(owner rpc.UID) error

Drop deletes all entries owned by the owner.

func (*DB) DropModule

func (db *DB) DropModule(module string) error

DropModule deletes all entries owned by the module.

func (*DB) Dump

func (db *DB) Dump() (map[rpc.UID]map[string][]byte, error)

Dump returns a Go map with the contents of the database.

func (*DB) DumpModule

func (db *DB) DumpModule(module string) (map[rpc.UID]map[string][]byte, error)

DumpModule returns a Go map with all the module's items.

func (*DB) Get

func (db *DB) Get(owner rpc.UID, item string) (val []byte, err error)

Get returns the owner's named item. Get returns sys.ErrNotFound if no item is found.

func (*DB) GetAll

func (db *DB) GetAll(owner rpc.UID) (vals map[string][]byte, err error)

GetAll returns all the owner's items.

func (*DB) Put

func (db *DB) Put(owner rpc.UID, item string, new []byte) (old []byte, written bool, err error)

Put returns the owner's named item and sets it to the new provided value if the values differ. It returns whether a write was performed.

func (*DB) Set

func (db *DB) Set(owner rpc.UID, item string, val []byte) error

Set sets the owner's named item to the provided value.

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

type PutMessage struct {
	Item  string `json:"item"`
	Value []byte `json:"value"`
}

PutMessage is the RPC message for putting a value into the store.

type PutResult

type PutResult struct {
	Value   []byte `json:"value"`
	Written bool   `json:"written"`
}

PutResult is the result of a PutMessage call.

type SetMessage

type SetMessage struct {
	Item  string `json:"item"`
	Value []byte `json:"value"`
}

SetMessage is the RPC message for setting a value into the store.

Jump to

Keyboard shortcuts

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