store

package
v0.0.0-...-9852d77 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: GPL-2.0, MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const OpEqual op = "="
View Source
const OpGt op = ">"
View Source
const OpGte op = ">="
View Source
const OpIn op = "in"
View Source
const OpLt op = "<"
View Source
const OpLte op = "<="
View Source
const OpNotEqual op = "<>"

Variables

View Source
var ErrNotFound error = errors.New("record not found")

Functions

This section is empty.

Types

type Cond

type Cond interface {
	GetQueryWithArgs() (string, []any)
}

type QueryJoiner

type QueryJoiner string
const QueryJoinerAnd QueryJoiner = "and"
const QueryJoinerOr QueryJoiner = "or"

func (QueryJoiner) GetQueryWithArgs

func (o QueryJoiner) GetQueryWithArgs() (string, []any)

type Row

type Row[T any] interface {
	// FieldsVals returns all fields of a struct for use with row.Scan.
	FieldsVals() []any
	ScanRow(row RowScanner) error
	*T
}

Row is a type constraint for types representing a single database row.

type RowScanner

type RowScanner interface {
	Scan(dest ...any) error
}

type Store

type Store[T any, R Row[T]] interface {
	Insert(obj T) (int64, error)
	Update(id int64, obj T) error
	GetMulti(ids []int64) ([]T, error)
	GetOne(id int64) (T, error)
	// FindWhere WhereConds must be either empty or joined by QueryJoiners
	FindWhere(...Cond) ([]T, error)
	DeleteMulti(ids []int64) error
	Close() error
}

Store is a generic interface to create, insert, update, retrieve, delete O. Note that O is a struct that might contain an array of primitive values or even structs

type WhereCond

type WhereCond struct {
	Field string
	Op    op
	Val   any
}

func (WhereCond) GetQueryWithArgs

func (o WhereCond) GetQueryWithArgs() (string, []any)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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