persistence

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxLimit      = 1000
	DefaultLimit  = 100
	DefaultOffset = 0
)

Variables

This section is empty.

Functions

func GetQueryArgsFromExprConstants

func GetQueryArgsFromExprConstants(constants []*exprpb.Constant) ([]interface{}, error)

GetQueryArgsFromExprConstants is a simple helper function to convert user-provided constant values to their string interface counterparts, which is helpful for use as placeholder values when writing DB queries. This will also filter out any duplicate tag values. An error will only be returned when a constant is not of the `exprpb.Constant_StringValue` type.

func GetTagsFromExpression

func GetTagsFromExpression(expr *exprpb.Expr) (tags []*exprpb.Constant, exprFunction string, err error)

GetTagsFromExpression takes in a pre-validated CEL expression and extracts the tags to filter upon. The CEL logical operator is also returned (`operators.LogicalAnd` or `operators.LogicalOr`). As a sanity check, an error will be returned when the expression does not conform to what is expected.

Types

type CRUD

type CRUD interface {
	// Get retrieves the value from store.
	// It returns ErrNotFound if key is not found.
	Get(ctx context.Context, key string) ([]byte, error)
	// Put sets key to value in the store.
	// If key is already present, it is overwritten.
	Put(ctx context.Context, key string, value []byte) error
	// Delete deletes the key and its associated value from store.
	// If key is not found, an ErrNotFound error is returned.
	Delete(ctx context.Context, key string) error
	// List returns all keys with prefix.
	List(ctx context.Context, prefix string, opts *ListOpts) (ListResult, error)
}

type Driver

type Driver int
const (
	SQLite3 Driver = iota
	Postgres
)

func (Driver) String

func (d Driver) String() string

type ErrNotFound

type ErrNotFound struct {
	Key string
}

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

type KVResult

type KVResult struct {
	Key   []byte
	Value []byte
}

type ListOpts

type ListOpts struct {
	// Limit is used to set the amount of results returned. Must be between zero & MaxLimit.
	Limit int

	// Offset is used for purposes of pagination. Must be a positive
	// number and zero is used to indicate the first page.
	Offset int

	// CEL expression used for filtering.
	//
	// When nil, no filtering of any kind will be done. When provided, the filter is
	// expected to be pre-validated for correctness. More specific validations can
	// occur later, e.g.: such validations that are specific to a particular resource.
	//
	// Read more: https://github.com/google/cel-spec
	Filter *exprpb.Expr
}

ListOpts defines various options that affect the results returned by a `CRUD.List()` call.

func NewDefaultListOpts

func NewDefaultListOpts() *ListOpts

type ListResult

type ListResult struct {
	KVList     []KVResult
	TotalCount int
}

type Persister

type Persister interface {
	CRUD
	Tx(context.Context) (Tx, error)
	Close() error
}

Persister is an interface to a KV store. A database must support the following operations: - Set key to a value - Get value based on a key - Transactions: Read and Write key-values in a transaction - List key-values based on a key prefix.

type Tx

type Tx interface {
	Commit() error
	Rollback() error
	CRUD
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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