psql

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNothingToUpdate = errors.New("nothing to update")

Functions

func Delete

func Delete(queryMods ...bob.Mod[*dialect.DeleteQuery]) bob.BaseQuery[*dialect.DeleteQuery]

func F

func F(name string, args ...any) *dialect.Function

func Insert

func Insert(queryMods ...bob.Mod[*dialect.InsertQuery]) bob.BaseQuery[*dialect.InsertQuery]

func LoadExceptColumns added in v0.13.0

func LoadExceptColumns(cols ...string) exceptColumnsOpt

func LoadOnlyColumns added in v0.13.0

func LoadOnlyColumns(cols ...string) onlyColumnsOpt

func RawQuery

func RawQuery(q string, args ...any) bob.BaseQuery[expr.Raw]

func Select

func Select(queryMods ...bob.Mod[*dialect.SelectQuery]) bob.BaseQuery[*dialect.SelectQuery]

func Update

func Update(queryMods ...bob.Mod[*dialect.UpdateQuery]) bob.BaseQuery[*dialect.UpdateQuery]

Types

type Expression added in v0.2.0

type Expression = dialect.Expression

func And

func And(args ...any) Expression

func Arg

func Arg(args ...any) Expression

func Concat

func Concat(args ...any) Expression

func Group

func Group(exps ...any) Expression

func Not

func Not(exp any) Expression

func Or

func Or(args ...any) Expression

func P

func P(exp any) Expression

func Placeholder

func Placeholder(n uint) Expression

func Quote

func Quote(ss ...string) Expression

func Raw

func Raw(query string, args ...any) Expression

func S

func S(s string) Expression

func X

func X(exp any, others ...any) Expression

type Filterable added in v0.13.0

type Filterable interface {
	AppendWhere(...any)
}

type Loader added in v0.13.0

type Loader func(ctx context.Context, exec bob.Executor, retrieved any) error

func (Loader) Apply added in v0.13.0

func (l Loader) Apply(q *dialect.SelectQuery)

func (Loader) Load added in v0.13.0

func (l Loader) Load(ctx context.Context, exec bob.Executor, retrieved any) error

type PreloadOption added in v0.13.0

type PreloadOption interface {
	// contains filtered or unexported methods
}

type Preloader added in v0.13.0

type Preloader func(ctx context.Context) (bob.Mod[*dialect.SelectQuery], scan.MapperMod, []bob.Loader)

func Preload added in v0.13.0

func Preload[T any, Ts ~[]T](rel orm.Relationship, cols orm.Columns, opts ...PreloadOption) Preloader

func (Preloader) Apply added in v0.13.0

func (l Preloader) Apply(q *dialect.SelectQuery)

type Table added in v0.13.0

type Table[T any, Tslice ~[]T, Topt any] struct {
	*View[T, Tslice]

	BeforeInsertHooks orm.Hooks[Topt]
	AfterInsertHooks  orm.Hooks[T]

	BeforeUpsertHooks orm.Hooks[Topt]
	AfterUpsertHooks  orm.Hooks[T]

	BeforeUpdateHooks orm.Hooks[T]
	AfterUpdateHooks  orm.Hooks[T]

	BeforeDeleteHooks orm.Hooks[T]
	AfterDeleteHooks  orm.Hooks[T]
	// contains filtered or unexported fields
}

The table contains extract information from the struct and contains caches ???

func NewTable added in v0.13.0

func NewTable[T any, Tslice ~[]T, Topt any](name0 string, nameX ...string) Table[T, Tslice, Topt]

func (*Table[T, Tslice, Topt]) Delete added in v0.13.0

func (t *Table[T, Tslice, Topt]) Delete(ctx context.Context, exec bob.Executor, row T) (int64, error)

Deletes the given model if columns is nil, every column is deleted

func (*Table[T, Tslice, Topt]) DeleteMany added in v0.13.0

func (t *Table[T, Tslice, Topt]) DeleteMany(ctx context.Context, exec bob.Executor, rows ...T) (int64, error)

Deletes the given models if columns is nil, every column is deleted

func (*Table[T, Tslice, Topt]) Insert added in v0.13.0

func (t *Table[T, Tslice, Topt]) Insert(ctx context.Context, exec bob.Executor, row Topt) (T, error)

Insert inserts a row into the table with only the set columns in Topt

func (*Table[T, Tslice, Topt]) InsertMany added in v0.13.0

func (t *Table[T, Tslice, Topt]) InsertMany(ctx context.Context, exec bob.Executor, rows ...Topt) (Tslice, error)

Insert inserts a row into the table with only the set columns in Topt

func (*Table[T, Tslice, Topt]) PKColumns added in v0.13.0

func (t *Table[T, Tslice, Topt]) PKColumns() orm.Columns

Returns a column list

func (*Table[T, Tslice, Topt]) Query added in v0.13.0

func (t *Table[T, Tslice, Topt]) Query(queryMods ...bob.Mod[*dialect.SelectQuery]) *TableQuery[T, Tslice, Topt]

Adds table name et al

func (*Table[T, Tslice, Topt]) Update added in v0.13.0

func (t *Table[T, Tslice, Topt]) Update(ctx context.Context, exec bob.Executor, cols []string, row T) (int64, error)

Updates the given model if columns is nil, every non-primary-key column is updated NOTE: values from the DB are not refreshed into the model

func (*Table[T, Tslice, Topt]) UpdateMany added in v0.13.0

func (t *Table[T, Tslice, Topt]) UpdateMany(ctx context.Context, exec bob.Executor, vals Topt, rows ...T) (int64, error)

Updates the given models if columns is nil, every column is updated NOTE: values from the DB are not refreshed into the models

func (*Table[T, Tslice, Topt]) Upsert added in v0.13.0

func (t *Table[T, Tslice, Topt]) Upsert(ctx context.Context, exec bob.Executor, updateOnConflict bool, conflictCols, updateCols []string, row Topt) (T, error)

Uses the optional columns to know what to insert If conflictCols is nil, it uses the primary key columns If updateCols is nil, it updates all the columns set in Topt if no column is set in Topt (i.e. INSERT DEFAULT VALUES), then it upserts all NonPK columns

func (*Table[T, Tslice, Topt]) UpsertMany added in v0.13.0

func (t *Table[T, Tslice, Topt]) UpsertMany(ctx context.Context, exec bob.Executor, updateOnConflict bool, conflictCols, updateCols []string, rows ...Topt) (Tslice, error)

Uses the optional columns to know what to insert If conflictCols is nil, it uses the primary key columns If updateCols is nil, it updates all the columns set in Topt if no column is set in Topt (i.e. INSERT DEFAULT VALUES), then it upserts all NonPK columns

type TableQuery added in v0.13.0

type TableQuery[T any, Ts ~[]T, Topt any] struct {
	ViewQuery[T, Ts]
	// contains filtered or unexported fields
}

func (*TableQuery[T, Tslice, Topt]) DeleteAll added in v0.13.0

func (t *TableQuery[T, Tslice, Topt]) DeleteAll(ctx context.Context, exec bob.Executor) (int64, error)

DeleteAll deletes all rows matched by the current query NOTE: Hooks cannot be run since the values are never retrieved

func (*TableQuery[T, Tslice, Topt]) UpdateAll added in v0.13.0

func (t *TableQuery[T, Tslice, Topt]) UpdateAll(ctx context.Context, exec bob.Executor, vals Topt) (int64, error)

UpdateAll updates all rows matched by the current query NOTE: Hooks cannot be run since the values are never retrieved

type View added in v0.13.0

type View[T any, Tslice ~[]T] struct {
	AfterSelectHooks orm.Hooks[T]
	// contains filtered or unexported fields
}

func NewView added in v0.13.0

func NewView[T any, Tslice ~[]T](name0 string, nameX ...string) View[T, Tslice]

func (*View[T, Tslice]) Columns added in v0.13.0

func (t *View[T, Tslice]) Columns() orm.Columns

Returns a column list

func (*View[T, Tslice]) Name added in v0.13.0

func (t *View[T, Tslice]) Name() Expression

func (*View[T, Tslice]) Prepare added in v0.13.0

func (*View[T, Tslice]) Prepare(ctx context.Context, exec bob.Preparer, q bob.Query) (bob.QueryStmt[T, Tslice], error)

Prepare a statement that will be mapped to the view's type

func (*View[T, Tslice]) Query added in v0.13.0

func (t *View[T, Tslice]) Query(queryMods ...bob.Mod[*dialect.SelectQuery]) *ViewQuery[T, Tslice]

Adds table name et al

type ViewQuery added in v0.13.0

type ViewQuery[T any, Ts ~[]T] struct {
	bob.BaseQuery[*dialect.SelectQuery]
	// contains filtered or unexported fields
}

func (*ViewQuery[T, Tslice]) All added in v0.13.0

func (f *ViewQuery[T, Tslice]) All(ctx context.Context, exec bob.Executor) (Tslice, error)

func (*ViewQuery[T, Tslice]) Count added in v0.13.0

func (f *ViewQuery[T, Tslice]) Count(ctx context.Context, exec bob.Executor) (int64, error)

func (*ViewQuery[T, Tslice]) Cursor added in v0.13.0

func (f *ViewQuery[T, Tslice]) Cursor(ctx context.Context, exec bob.Executor) (scan.ICursor[T], error)

func (*ViewQuery[T, Tslice]) Exists added in v0.13.0

func (f *ViewQuery[T, Tslice]) Exists(ctx context.Context, exec bob.Executor) (bool, error)

func (*ViewQuery[T, Tslice]) One added in v0.13.0

func (f *ViewQuery[T, Tslice]) One(ctx context.Context, exec bob.Executor) (T, error)

func (*ViewQuery[T, Tslice]) Prepare added in v0.13.0

func (f *ViewQuery[T, Tslice]) Prepare(ctx context.Context, exec bob.Preparer) (bob.QueryStmt[T, Tslice], error)

type WhereMod added in v0.13.0

type WhereMod[Q Filterable, C any] struct {
	// contains filtered or unexported fields
}

func Where added in v0.13.0

func Where[Q Filterable, C any](name Expression) WhereMod[Q, C]

func (WhereMod[Q, C]) EQ added in v0.13.0

func (w WhereMod[Q, C]) EQ(val C) bob.Mod[Q]

func (WhereMod[Q, C]) GT added in v0.13.0

func (w WhereMod[Q, C]) GT(val C) bob.Mod[Q]

func (WhereMod[Q, C]) GTE added in v0.13.0

func (w WhereMod[Q, C]) GTE(val C) bob.Mod[Q]

func (WhereMod[Q, C]) In added in v0.13.0

func (w WhereMod[Q, C]) In(slice ...C) bob.Mod[Q]

func (WhereMod[Q, C]) LT added in v0.13.0

func (w WhereMod[Q, C]) LT(val C) bob.Mod[Q]

func (WhereMod[Q, C]) LTE added in v0.13.0

func (w WhereMod[Q, C]) LTE(val C) bob.Mod[Q]

func (WhereMod[Q, C]) NE added in v0.13.0

func (w WhereMod[Q, C]) NE(val C) bob.Mod[Q]

func (WhereMod[Q, C]) NotIn added in v0.13.0

func (w WhereMod[Q, C]) NotIn(slice ...C) bob.Mod[Q]

type WhereNullMod added in v0.13.0

type WhereNullMod[Q interface {
	AppendWhere(e ...any)
}, C any] struct {
	WhereMod[Q, C]
}

func WhereNull added in v0.13.0

func WhereNull[Q Filterable, C any](name Expression) WhereNullMod[Q, C]

func (WhereNullMod[Q, C]) IsNotNull added in v0.13.0

func (w WhereNullMod[Q, C]) IsNotNull() bob.Mod[Q]

func (WhereNullMod[Q, C]) IsNull added in v0.13.0

func (w WhereNullMod[Q, C]) IsNull() bob.Mod[Q]

Directories

Path Synopsis
delete
qm
insert
qm
select
qm
update
qm

Jump to

Keyboard shortcuts

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