common

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: Apache-2.0 Imports: 21 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyCondition = emptyCondition{}

Functions

func CreateParamsMatrix

func CreateParamsMatrix(fields, rows int, offset int) string

func InitSchema

func InitSchema(db *sql.DB, schemas ...string) (err error)

func JoinCol

func JoinCol(tableName string, field FieldName) string

func NewInterpreter

func NewInterpreter() *interpreter

func NewUnversionedReadScanner

func NewUnversionedReadScanner() *unversionedReadScanner

func NewUnversionedValueScanner

func NewUnversionedValueScanner() *unversionedValueScanner

func NewVersionedMetadataValueScanner

func NewVersionedMetadataValueScanner() *versionedMetadataValueScanner

func NewVersionedReadScanner

func NewVersionedReadScanner() *versionedReadScanner

func NewVersionedValueScanner

func NewVersionedValueScanner() *versionedValueScanner

func TestCases

func TestCases(t *testing.T,
	versionedProvider provider[driver.TransactionalVersionedPersistence],
	unversionedProvider provider[driver.UnversionedPersistence],
	unversionedNotifierProvider provider[driver.UnversionedNotifier],
	versionedNotifierProvider provider[driver.VersionedNotifier],
	baseUnpacker func(p driver.UnversionedPersistence) *BasePersistence[driver.UnversionedValue, driver.UnversionedRead])

func ToInts

func ToInts[T constraints.Integer](in []T) []int

func Where

func Where(c Condition) (string, []any)

Types

type BasePersistence

type BasePersistence[V any, R any] struct {
	*common.BaseDB[*sql.Tx]

	ValueScanner ValueScanner[V]
	// contains filtered or unexported fields
}

func NewBasePersistence

func NewBasePersistence[V any, R any](writeDB *sql.DB, readDB *sql.DB, table string, readScanner readScanner[R], valueScanner ValueScanner[V], errorWrapper driver.SQLErrorWrapper, ci Interpreter, newTransaction func() (*sql.Tx, error)) *BasePersistence[V, R]

func (*BasePersistence[V, R]) Close

func (db *BasePersistence[V, R]) Close() error

func (*BasePersistence[V, R]) DeleteState

func (db *BasePersistence[V, R]) DeleteState(ns driver2.Namespace, key driver2.PKey) error

func (*BasePersistence[V, R]) DeleteStateWithTx

func (db *BasePersistence[V, R]) DeleteStateWithTx(tx *sql.Tx, ns driver2.Namespace, key driver2.PKey) error

func (*BasePersistence[V, R]) DeleteStates

func (db *BasePersistence[V, R]) DeleteStates(namespace driver2.Namespace, keys ...driver2.PKey) map[driver2.PKey]error

func (*BasePersistence[V, R]) DeleteStatesWithTx

func (db *BasePersistence[V, R]) DeleteStatesWithTx(tx *sql.Tx, namespace driver2.Namespace, keys ...driver2.PKey) map[driver2.PKey]error

func (*BasePersistence[V, R]) Exec

func (db *BasePersistence[V, R]) Exec(query string, args ...any) (sql.Result, error)

func (*BasePersistence[V, R]) Exists

func (db *BasePersistence[V, R]) Exists(ns driver2.Namespace, key driver2.PKey) (bool, error)

func (*BasePersistence[V, R]) GetState

func (db *BasePersistence[V, R]) GetState(namespace driver2.Namespace, key string) (V, error)

func (*BasePersistence[V, R]) GetStateRangeScanIterator

func (db *BasePersistence[V, R]) GetStateRangeScanIterator(ns driver2.Namespace, startKey, endKey string) (collections.Iterator[*R], error)

func (*BasePersistence[V, R]) GetStateSetIterator

func (db *BasePersistence[V, R]) GetStateSetIterator(ns driver2.Namespace, keys ...driver2.PKey) (collections.Iterator[*R], error)

func (*BasePersistence[V, R]) InitSchema

func (db *BasePersistence[V, R]) InitSchema(query string) error

func (*BasePersistence[V, R]) SetState

func (db *BasePersistence[V, R]) SetState(ns driver2.Namespace, pkey driver2.PKey, value V) error

func (*BasePersistence[V, R]) SetStateWithTx

func (db *BasePersistence[V, R]) SetStateWithTx(tx *sql.Tx, ns driver2.Namespace, pkey string, value V) error

func (*BasePersistence[V, R]) SetStates

func (db *BasePersistence[V, R]) SetStates(ns driver2.Namespace, kvs map[driver2.PKey]V) map[driver2.PKey]error

func (*BasePersistence[V, R]) Stats

func (db *BasePersistence[V, R]) Stats() any

func (*BasePersistence[V, R]) TableName

func (db *BasePersistence[V, R]) TableName() string

func (*BasePersistence[V, R]) UpsertStateWithTx

func (db *BasePersistence[V, R]) UpsertStateWithTx(tx *sql.Tx, ns driver2.Namespace, pkey driver2.PKey, keys []string, values []any) error

func (*BasePersistence[V, R]) UpsertStates

func (db *BasePersistence[V, R]) UpsertStates(ns driver2.Namespace, valueKeys []string, vals map[driver2.PKey][]any) map[driver2.PKey]error

type Condition

type Condition interface {
	ToString(*int) string

	Params() []any
	// contains filtered or unexported methods
}

type ConstCondition

type ConstCondition string

func (ConstCondition) Params

func (c ConstCondition) Params() []any

func (ConstCondition) ToString

func (c ConstCondition) ToString(*int) string

type FieldName

type FieldName = string

type Interpreter

type Interpreter interface {
	Cmp(field FieldName, symbol string, value any) Condition
	And(conditions ...Condition) Condition
	Or(conditions ...Condition) Condition
	In(field FieldName, vals []any) Condition
	InStrings(field FieldName, vals []string) Condition
	InInts(field FieldName, vals []int) Condition
	InTuple(fields []FieldName, vals []Tuple) Condition
	BetweenStrings(field FieldName, startKey, endKey string) Condition
	BetweenInts(field FieldName, startKey, endKey int) Condition
}

type Opts

type Opts struct {
	Driver          SQLDriverType
	DataSource      string
	TablePrefix     string
	SkipCreateTable bool
	SkipPragmas     bool
	MaxOpenConns    int
	MaxIdleConns    int
	MaxIdleTime     time.Duration
}

func GetOpts

func GetOpts(config driver.Config, optsKey string) (*Opts, error)

type SQLDriverType

type SQLDriverType string

type TableNameCreator

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

func NewTableNameCreator

func NewTableNameCreator(prefix string) (*TableNameCreator, error)

func (*TableNameCreator) GetTableName

func (c *TableNameCreator) GetTableName(name string) (string, bool)

func (*TableNameCreator) MustGetTableName

func (c *TableNameCreator) MustGetTableName(name string) string

type Tuple

type Tuple = []any

type UnversionedPersistence

type UnversionedPersistence struct {
	driver.BasePersistence[driver.UnversionedValue, driver.UnversionedRead]
	// contains filtered or unexported fields
}

func NewUnversioned

func NewUnversioned(readDB *sql.DB, writeDB *sql.DB, table string, errorWrapper driver.SQLErrorWrapper, ci Interpreter) *UnversionedPersistence

func (*UnversionedPersistence) CreateSchema

func (db *UnversionedPersistence) CreateSchema() error

type ValueScanner

type ValueScanner[V any] interface {

	// WriteValue writes the values of the V struct in the order given by the Columns method
	WriteValue(V) []any
	// contains filtered or unexported methods
}

type VersionedPersistence

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

func NewVersioned

func NewVersioned(readDB *sql.DB, writeDB *sql.DB, table string, errorWrapper driver.SQLErrorWrapper, ci Interpreter) *VersionedPersistence

func NewVersionedPersistence

func NewVersionedPersistence(base basePersistence[driver.VersionedValue, driver.VersionedRead], table string, errorWrapper driver.SQLErrorWrapper, readDB *sql.DB, writeDB *sql.DB) *VersionedPersistence

func (*VersionedPersistence) CreateSchema

func (db *VersionedPersistence) CreateSchema() error

func (*VersionedPersistence) GetStateMetadata

func (db *VersionedPersistence) GetStateMetadata(namespace driver2.Namespace, key driver2.PKey) (driver2.Metadata, driver2.RawVersion, error)

func (*VersionedPersistence) NewWriteTransaction

func (db *VersionedPersistence) NewWriteTransaction() (driver.WriteTransaction, error)

func (*VersionedPersistence) SetStateMetadata

func (db *VersionedPersistence) SetStateMetadata(ns driver2.Namespace, key driver2.PKey, metadata driver2.Metadata, version driver2.RawVersion) error

func (*VersionedPersistence) SetStateMetadatas

func (*VersionedPersistence) Stats

func (db *VersionedPersistence) Stats() any

type WriteTransaction

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

func NewWriteTransaction

func NewWriteTransaction(txn *sql.Tx, db versionedPersistence) *WriteTransaction

func (*WriteTransaction) Commit

func (w *WriteTransaction) Commit() error

func (*WriteTransaction) DeleteState

func (w *WriteTransaction) DeleteState(ns driver2.Namespace, key driver2.PKey) error

func (*WriteTransaction) Discard

func (w *WriteTransaction) Discard() error

func (*WriteTransaction) SetState

func (w *WriteTransaction) SetState(namespace driver2.Namespace, key driver2.PKey, value driver.VersionedValue) error

Jump to

Keyboard shortcuts

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