store

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver interface {
	Exec(record TxRecord, handler TxHandler) (tx Tx, result any, err error)
	Migrate(statements []string) error
}

Driver represents an underlying storage driver

type ReadTx

type ReadTx interface {
	Select(out any, query string, args ...any) error
	Get(out any, query string, args ...any) error
}

ReadTx is a read-only transaction

type ReadWriteTx

type ReadWriteTx interface {
	ReadTx
	Exec(query string, args ...any) (int64, error)
}

ReadWriteTx is a transaction for read or write transactions

type Store

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

Store is a distributed, replicated datastore for libsdk applications

func New

func New(driver Driver, replayer fabric.ReplayConnection) *Store

New creates a new Store with the given driver

func (*Store) Exec

func (s *Store) Exec(name string, args ...any) (any, error)

Exec performs a two-stage distributed transaction based on a registered named TxHandler. The Tx is distributed using the fabric and, upon confirmation of successful distribution, applied to the local store replica. The result or error of the TxHandler is returned. Non-errored call to Exec guarantees that replication succeeded.

func (*Store) Register

func (s *Store) Register(name string, handler TxHandler) error

Register registers the given transaction under the given name. name must be unique, attempt to re-register with same name results in an error.

func (*Store) Start

func (s *Store) Start(migrations []string) error

Start starts the store replay loop

type Tx

type Tx interface {
	Read() ReadTx
	ReadWrite() ReadWriteTx
	DidWrite() bool
}

Tx is an object that can itself kick off a read-only transaction or a read-write transaction which is managed by the underlying driver

type TxHandler

type TxHandler func(tx Tx, args ...any) (result any, err error)

TxHandler is a function that executes a named transaction

type TxRecord

type TxRecord struct {
	UUID string `json:"uuid"`
	Name string `json:"name"`
	Args []any  `json:"args"`
}

TxRecord is a serializable transaction for replication purposes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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