persistence

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 2 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecordNotFound         = errors.New("record not in the database")
	ErrConstraintFailed       = errors.New("constraint failed")
	ErrUniqueConstraintFailed = errors.New("unique constraint failed")
	ErrUnsupportedType        = errors.New("unsupported type")
)

Functions

func BuildConds added in v1.9.5

func BuildConds(query []string, args []any) (conds []any)

BuildConds prepares the conds used in [Storage.List] out of arrays of query and args.

Types

type Storage added in v1.4.0

type Storage interface {

	// Create creates a new object and put it into the DB
	Create(r any) error

	// Save updates the record r (workaround with conds needed that e.g. user has no specific ID, and we can not touch
	// the generated (gRPC) code s.t. user.username has primary key annotation)
	Save(r any, conds ...any) error

	// Update updates the record with given id of the DB with non-zero values in r
	Update(r any, conds ...any) error

	// Get gets the record which meet the given conditions
	Get(r any, conds ...any) error

	// List lists all records in database which meet the (optionally) given conditions with a certain limit after an
	// offset. If no limit is desired, the value -1 can be specified. Optionally set orderBy (column) and asc (true =
	// ascending, false = descending) for ordering the results.
	// Whitelist the set of possible column names to avoid injections.
	List(r any, orderBy string, asc bool, offset int, limit int, conds ...any) error

	// Count counts the number of records which meet the (optionally) given conditions
	Count(r any, conds ...any) (int64, error)

	// Delete deletes the record with given id of the DB
	Delete(r any, conds ...any) error

	// Raw executes a raw SQL statement and stores the result in r
	Raw(r any, query string, args ...any) error
}

Storage comprises a database interface TODO(all): I think with generics we could get sth. like `[T]Get(r T, id string) T` which is maybe more intuitive then changing the parameter? Maybe its only my impression

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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