psql

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Case added in v0.29.0

SQL: CASE WHEN a THEN b ELSE c END Go: psql.Case().When("a", "b").Else("c")

func Delete

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

func F

func F(name string, args ...any) mods.Moddable[*dialect.Function]

F creates a function expression with the given name and args

SQL: generate_series(1, 3)
Go: psql.F("generate_series", 1, 3)

func Insert

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

func RawQuery

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

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]

func UseSchema added in v0.15.0

func UseSchema(ctx context.Context, schema string) context.Context

UseSchema modifies a context to add a schema that will be used when a tablle/view was generated with an empty schema

func WhereAnd added in v0.22.0

func WhereAnd[Q Filterable](whereMods ...mods.Where[Q]) mods.Where[Q]

func WhereOr added in v0.22.0

func WhereOr[Q Filterable](whereMods ...mods.Where[Q]) mods.Where[Q]

Types

type Expression added in v0.2.0

type Expression = dialect.Expression

func And

func And(args ...bob.Expression) Expression

SQL: a AND b AND c Go: psql.And("a", "b", "c")

func Arg

func Arg(args ...any) Expression

SQL: $1, $2, $3 Go: psql.Args("a", "b", "c")

func ArgGroup added in v0.15.0

func ArgGroup(args ...any) Expression

SQL: ($1, $2, $3) Go: psql.ArgGroup("a", "b", "c")

func Cast added in v0.28.0

func Cast(exp bob.Expression, typname string) Expression

SQL: CAST(a AS int) Go: psql.Cast("a", "int")

func Concat

func Concat(args ...bob.Expression) Expression

SQL: a || b || c Go: psql.Concat("a", "b", "c")

func Group

func Group(exps ...bob.Expression) Expression

SQL: (a, b) Go: psql.Group("a", "b")

func Not

func Not(exp bob.Expression) Expression

SQL: NOT true Go: psql.Not("true")

func Or

func Or(args ...bob.Expression) Expression

SQL: a OR b OR c Go: psql.Or("a", "b", "c")

func Placeholder

func Placeholder(n uint) Expression

SQL: $1, $2, $3 Go: psql.Placeholder(3)

func Quote

func Quote(ss ...string) Expression

SQL: "table"."column" Go: psql.Quote("table", "column")

func Raw

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

SQL: where a = $1 Go: psql.Raw("where a = ?", "something")

func S

func S(s string) Expression

S creates a string literal SQL: 'a string' Go: psql.S("a string")

type Filterable added in v0.13.0

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

type Loader added in v0.13.0

Loader builds a query mod that makes an extra query after the object is retrieved it can be used to prevent N+1 queries by loading relationships in batches

type PreloadOption added in v0.13.0

type PreloadOption = internal.PreloadOption[*dialect.SelectQuery]

Modifies preloading relationships

func PreloadAs added in v0.27.0

func PreloadAs(alias string) PreloadOption

func PreloadExcept added in v0.20.0

func PreloadExcept(cols ...string) PreloadOption

func PreloadOnly added in v0.20.0

func PreloadOnly(cols ...string) PreloadOption

func PreloadWhere added in v0.20.0

func PreloadWhere(f ...func(from, to string) []bob.Expression) PreloadOption

type PreloadSettings added in v0.19.0

type PreloadSettings = internal.PreloadSettings[*dialect.SelectQuery]

Settings for preloading relationships

type Preloader added in v0.13.0

type Preloader = internal.Preloader[*dialect.SelectQuery]

Preloader builds a query mod that modifies the original query to retrieve related fields while it can be used as a queryMod, it does not have any direct effect. if using manually, the ApplyPreload method should be called with the query's context AFTER other mods have been applied

func Preload added in v0.13.0

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

type Table added in v0.13.0

type Table[T orm.Model, Tslice ~[]T, Tset setter[T]] struct {
	*View[T, Tslice]

	BeforeInsertHooks bob.Hooks[Tset, bob.SkipModelHooksKey]
	AfterInsertHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]

	BeforeUpdateHooks bob.Hooks[Tslice, bob.SkipModelHooksKey]
	AfterUpdateHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]

	BeforeDeleteHooks bob.Hooks[Tslice, bob.SkipModelHooksKey]
	AfterDeleteHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]

	InsertQueryHooks bob.Hooks[*dialect.InsertQuery, bob.SkipQueryHooksKey]
	UpdateQueryHooks bob.Hooks[*dialect.UpdateQuery, bob.SkipQueryHooksKey]
	DeleteQueryHooks bob.Hooks[*dialect.DeleteQuery, bob.SkipQueryHooksKey]
	// 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 orm.Model, Tset setter[T]](schema, tableName string) *Table[T, []T, Tset]

func NewTablex added in v0.15.0

func NewTablex[T orm.Model, Tslice ~[]T, Tset setter[T]](schema, tableName string) *Table[T, Tslice, Tset]

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

func (t *Table[T, Tslice, Tset]) Delete(queryMods ...bob.Mod[*dialect.DeleteQuery]) *orm.Query[*dialect.DeleteQuery, T, Tslice]

Starts a Delete query for this table

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

func (t *Table[T, Tslice, Tset]) Insert(queryMods ...bob.Mod[*dialect.InsertQuery]) *orm.Query[*dialect.InsertQuery, T, Tslice]

Starts an insert query for this table

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

func (t *Table[T, Tslice, Tset]) Update(queryMods ...bob.Mod[*dialect.UpdateQuery]) *orm.Query[*dialect.UpdateQuery, T, Tslice]

Starts an Update query for this table

type View added in v0.13.0

type View[T any, Tslice ~[]T] struct {
	AfterSelectHooks bob.Hooks[Tslice, bob.SkipModelHooksKey]
	SelectQueryHooks bob.Hooks[*dialect.SelectQuery, bob.SkipQueryHooksKey]
	// contains filtered or unexported fields
}

func NewView added in v0.13.0

func NewView[T any](schema, tableName string) *View[T, []T]

func NewViewx added in v0.15.0

func NewViewx[T any, Tslice ~[]T](schema, tableName string) *View[T, Tslice]

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

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

Returns a column list

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

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

func (*View[T, Tslice]) NameAs added in v0.15.0

func (v *View[T, Tslice]) NameAs() bob.Expression

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

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

Starts a select query

type ViewQuery added in v0.13.0

type ViewQuery[T any, Ts ~[]T] struct {
	orm.Query[*dialect.SelectQuery, T, Ts]
}

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

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

Count the number of matching rows

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

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

Exists checks if there is any matching row

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) mods.Where[Q]

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

func (w WhereMod[Q, C]) GT(val C) mods.Where[Q]

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

func (w WhereMod[Q, C]) GTE(val C) mods.Where[Q]

func (WhereMod[Q, C]) ILike added in v0.19.0

func (w WhereMod[Q, C]) ILike(val C) mods.Where[Q]

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

func (w WhereMod[Q, C]) In(slice ...C) mods.Where[Q]

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

func (w WhereMod[Q, C]) LT(val C) mods.Where[Q]

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

func (w WhereMod[Q, C]) LTE(val C) mods.Where[Q]

func (WhereMod[Q, C]) Like added in v0.19.0

func (w WhereMod[Q, C]) Like(val C) mods.Where[Q]

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

func (w WhereMod[Q, C]) NE(val C) mods.Where[Q]

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

func (w WhereMod[Q, C]) NotIn(slice ...C) mods.Where[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() mods.Where[Q]

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

func (w WhereNullMod[Q, C]) IsNull() mods.Where[Q]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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