db

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithUnitOfWork

func WithUnitOfWork(ctx context.Context, uow UnitOfWork) context.Context

Types

type Batch

type Batch []*BatchItem

Batch a list of batch query items

func (*Batch) Add added in v1.2.0

func (b *Batch) Add(collection string, v interface{}, opts ...BatchOption)

Add an item

func (*Batch) All

func (b *Batch) All(spec Spec, v interface{}, opts ...BatchOption)

All append a query expecting multiple results

func (*Batch) Do

func (b *Batch) Do(spec Spec, opts ...BatchOption)

Do append a query expecting a single result

func (*Batch) Edit added in v1.2.0

func (b *Batch) Edit(collection string, spec Spec, v interface{}, opts ...BatchOption)

Edit an item

func (*Batch) One

func (b *Batch) One(spec Spec, v interface{}, opts ...BatchOption)

One append a query expecting a single result

type BatchItem

type BatchItem struct {
	Spec     Spec
	Value    interface{}
	One      bool
	Skip     bool
	Optional bool
	Defer    bool
}

BatchItem a single batch query

type BatchOption

type BatchOption func(item *BatchItem)

BatchOption for custom query configuration

func Optional added in v1.1.3

func Optional(flag bool) BatchOption

Optional marks the item as optional ignoring client errors

type DB

type DB interface {
	Repository() Repository
	Begin(ctx context.Context, opts ...TxOption) (UnitOfWork, error)
}

DB provides instances of transactions and repositories.

type Repository

type Repository interface {
	One(ctx context.Context, spec Spec, v interface{}) error
	All(ctx context.Context, spec Spec, v interface{}) error
	Add(ctx context.Context, collection string, v interface{}) error
	Edit(ctx context.Context, collection string, spec Spec, v interface{}) error
	Remove(ctx context.Context, collection string, spec Spec) error
	Batch(ctx context.Context, batch Batch) error
}

Repository abstraction for a collection of objects.

type Spec

type Spec interface {
	Id() interface{}
	ToSql() (string, []interface{}, error)
}

Spec for querying objects

func Defer added in v1.1.4

func Defer(id interface{}, fn func() squirrel.Sqlizer) Spec

Defer creates a deferred execution spec

func Sql added in v1.2.0

func Sql(literal string, args ...interface{}) Spec

Sql is a helper for creating a spec from an sql literal

func Sqlizer added in v1.2.0

func Sqlizer(sqlizer squirrel.Sqlizer) Spec

Sqlizer is a helper for creating a spec

type TxConfig

type TxConfig struct {
	ReadOnly bool
}

TxConfig a configuration for transactions

type TxOption

type TxOption func(conf *TxConfig)

TxOption a configuration option for transactions

func WithReadOnly

func WithReadOnly(flag bool) TxOption

WithReadOnly use read-only transaction

type UnitOfWork

type UnitOfWork interface {
	Tx() interface{}
	Commit(ctx context.Context) error
	Rollback(ctx context.Context)
}

UnitOfWork to do

func UnitOfWorkValue

func UnitOfWorkValue(ctx context.Context) (UnitOfWork, bool)

Directories

Path Synopsis
pg

Jump to

Keyboard shortcuts

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