Documentation ¶
Index ¶
- Variables
- func Delete(queryMods ...bob.Mod[*dialect.DeleteQuery]) bob.BaseQuery[*dialect.DeleteQuery]
- func ExceptColumns(cols ...string) exceptColumnsOpt
- func F(name string, args ...any) *dialect.Function
- func Insert(queryMods ...bob.Mod[*dialect.InsertQuery]) bob.BaseQuery[*dialect.InsertQuery]
- func OnlyColumns(cols ...string) onlyColumnsOpt
- func RawQuery(q string, args ...any) bob.BaseQuery[expr.Raw]
- func Select(queryMods ...bob.Mod[*dialect.SelectQuery]) bob.BaseQuery[*dialect.SelectQuery]
- func Update(queryMods ...bob.Mod[*dialect.UpdateQuery]) bob.BaseQuery[*dialect.UpdateQuery]
- type Expression
- func And(args ...any) Expression
- func Arg(args ...any) Expression
- func ArgGroup(args ...any) Expression
- func Concat(args ...any) Expression
- func Group(exps ...any) Expression
- func Not(exp any) Expression
- func Or(args ...any) Expression
- func P(exp any) Expression
- func Placeholder(n uint) Expression
- func Quote(ss ...string) Expression
- func Raw(query string, args ...any) Expression
- func S(s string) Expression
- func X(exp any, others ...any) Expression
- type Filterable
- type Loader
- type PreloadOption
- type Preloader
- type Table
- func (t *Table[T, Tslice, Tset]) Delete(ctx context.Context, exec bob.Executor, row T) (int64, error)
- func (t *Table[T, Tslice, Tset]) DeleteMany(ctx context.Context, exec bob.Executor, rows ...T) (int64, error)
- func (t *Table[T, Tslice, Tset]) Insert(ctx context.Context, exec bob.Executor, row Tset) (T, error)
- func (t *Table[T, Tslice, Tset]) InsertMany(ctx context.Context, exec bob.Executor, rows ...Tset) (int64, error)
- func (t *Table[T, Tslice, Tset]) Query(ctx context.Context, exec bob.Executor, ...) *TableQuery[T, Tslice, Tset]
- func (t *Table[T, Tslice, Tset]) Update(ctx context.Context, exec bob.Executor, row T, cols ...string) (int64, error)
- func (t *Table[T, Tslice, Tset]) UpdateMany(ctx context.Context, exec bob.Executor, vals Tset, rows ...T) (int64, error)
- func (t *Table[T, Tslice, Tset]) Upsert(ctx context.Context, exec bob.Executor, updateOnConflict bool, ...) (T, error)
- func (t *Table[T, Tslice, Tset]) UpsertMany(ctx context.Context, exec bob.Executor, updateOnConflict bool, ...) (int64, error)
- type TableQuery
- type View
- func (v *View[T, Tslice]) Columns() orm.Columns
- func (v *View[T, Tslice]) Name(ctx context.Context) bob.Expression
- func (v *View[T, Tslice]) NameAs(ctx context.Context) bob.Expression
- func (v *View[T, Tslice]) Prepare(ctx context.Context, exec bob.Preparer, ...) (bob.QueryStmt[T, Tslice], error)
- func (v *View[T, Tslice]) PrepareQuery(ctx context.Context, exec bob.Preparer, q bob.Query) (bob.QueryStmt[T, Tslice], error)
- func (v *View[T, Tslice]) Query(ctx context.Context, exec bob.Executor, ...) *ViewQuery[T, Tslice]
- type ViewQuery
- func (v *ViewQuery[T, Tslice]) All() (Tslice, error)
- func (v *ViewQuery[T, Tslice]) Count() (int64, error)
- func (v *ViewQuery[T, Tslice]) Cursor() (scan.ICursor[T], error)
- func (v *ViewQuery[T, Tslice]) Exists() (bool, error)
- func (v *ViewQuery[T, Tslice]) One() (T, error)
- func (v *ViewQuery[T, Ts]) WriteQuery(w io.Writer, start int) ([]any, error)
- func (v *ViewQuery[T, Ts]) WriteSQL(w io.Writer, d bob.Dialect, start int) ([]any, error)
- type WhereMod
- func (w WhereMod[Q, C]) EQ(val C) bob.Mod[Q]
- func (w WhereMod[Q, C]) GT(val C) bob.Mod[Q]
- func (w WhereMod[Q, C]) GTE(val C) bob.Mod[Q]
- func (w WhereMod[Q, C]) In(slice ...C) bob.Mod[Q]
- func (w WhereMod[Q, C]) LT(val C) bob.Mod[Q]
- func (w WhereMod[Q, C]) LTE(val C) bob.Mod[Q]
- func (w WhereMod[Q, C]) NE(val C) bob.Mod[Q]
- func (w WhereMod[Q, C]) NotIn(slice ...C) bob.Mod[Q]
- type WhereNullMod
Constants ¶
This section is empty.
Variables ¶
var ( ErrNothingToUpdate = errors.New("nothing to update") ErrCannotRetrieveRow = errors.New("cannot retrieve inserted row") )
Functions ¶
func Delete ¶
func Delete(queryMods ...bob.Mod[*dialect.DeleteQuery]) bob.BaseQuery[*dialect.DeleteQuery]
func ExceptColumns ¶ added in v0.15.0
func ExceptColumns(cols ...string) exceptColumnsOpt
func F ¶
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 OnlyColumns ¶ added in v0.15.0
func OnlyColumns(cols ...string) onlyColumnsOpt
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 ArgGroup ¶ added in v0.15.0
func ArgGroup(args ...any) Expression
SQL: ($1, $2, $3) Go: psql.ArgGroup("a", "b", "c")
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")
func X ¶
func X(exp any, others ...any) Expression
X is a flexible starter that joins the given expressions with a space
type Filterable ¶ added in v0.15.0
type Filterable interface {
AppendWhere(...any)
}
type Loader ¶ added in v0.15.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
func (Loader) Apply ¶ added in v0.15.0
func (l Loader) Apply(q *dialect.SelectQuery)
Apply satisfies the bob.Mod[*dialect.SelectQuery] interface
type PreloadOption ¶ added in v0.15.0
type PreloadOption interface {
// contains filtered or unexported methods
}
type Preloader ¶ added in v0.15.0
type Preloader func(ctx context.Context) (bob.Mod[*dialect.SelectQuery], scan.MapperMod, []bob.Loader)
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.15.0
func Preload[T any, Ts ~[]T](rel orm.Relationship, cols []string, opts ...PreloadOption) Preloader
func (Preloader) Apply ¶ added in v0.15.0
func (l Preloader) Apply(s *dialect.SelectQuery)
Apply satisfies bob.Mod[*dialect.SelectQuery]. included for convenience, does not have any effect by itself to preload with custom queries, the ApplyPreload method should be used
func (Preloader) ApplyPreload ¶ added in v0.15.0
func (l Preloader) ApplyPreload(ctx context.Context, q *dialect.SelectQuery)
ApplyPreload does a few things to enable preloading 1. It modifies the query to join the preloading table and the extra columns to retrieve 2. It modifies the mapper to scan the new columns. 3. It calls the original object's Preload method with the loaded object
type Table ¶ added in v0.15.0
type Table[T any, Tslice ~[]T, Tset any] struct { *View[T, Tslice] BeforeInsertHooks orm.Hooks[Tset] BeforeUpsertHooks orm.Hooks[Tset] // NOTE: This is not called by InsertMany() AfterInsertOneHooks orm.Hooks[T] // NOTE: This is not called by UpsertMany() AfterUpsertOneHooks 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 (*Table[T, Tslice, Tset]) Delete ¶ added in v0.15.0
func (t *Table[T, Tslice, Tset]) 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, Tset]) DeleteMany ¶ added in v0.15.0
func (t *Table[T, Tslice, Tset]) 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, Tset]) Insert ¶ added in v0.15.0
func (t *Table[T, Tslice, Tset]) Insert(ctx context.Context, exec bob.Executor, row Tset) (T, error)
Insert inserts a row into the table with only the set columns in Tset
- If the table has an AUTO_INCREMENT column, the inserted row is retrieved using the lastInsertID
- If there is no AUTO_INCREMENT but the table has a unique indes that has all columns set in the setional row, then the values of the unique columns are used to retrieve the inserted row
If there is none of the above methods are possible, a zero value and ErrCannotRetrieveRow is returned after a successful insert
func (*Table[T, Tslice, Tset]) InsertMany ¶ added in v0.15.0
func (t *Table[T, Tslice, Tset]) InsertMany(ctx context.Context, exec bob.Executor, rows ...Tset) (int64, error)
InsertMany inserts multiple row into the table with only the set columns in Tset and returns the number of inserted rows
func (*Table[T, Tslice, Tset]) Query ¶ added in v0.15.0
func (t *Table[T, Tslice, Tset]) Query(ctx context.Context, exec bob.Executor, queryMods ...bob.Mod[*dialect.SelectQuery]) *TableQuery[T, Tslice, Tset]
Adds table name et al
func (*Table[T, Tslice, Tset]) Update ¶ added in v0.15.0
func (t *Table[T, Tslice, Tset]) Update(ctx context.Context, exec bob.Executor, row T, cols ...string) (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, Tset]) UpdateMany ¶ added in v0.15.0
func (t *Table[T, Tslice, Tset]) UpdateMany(ctx context.Context, exec bob.Executor, vals Tset, 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, Tset]) Upsert ¶ added in v0.15.0
func (t *Table[T, Tslice, Tset]) Upsert(ctx context.Context, exec bob.Executor, updateOnConflict bool, updateCols []string, row Tset) (T, error)
Uses the setional columns to know what to insert If updateCols is nil, it updates all the columns set in Tset if no column is set in Tset (i.e. INSERT DEFAULT VALUES), then it upserts all NonPK columns
func (*Table[T, Tslice, Tset]) UpsertMany ¶ added in v0.15.0
func (t *Table[T, Tslice, Tset]) UpsertMany(ctx context.Context, exec bob.Executor, updateOnConflict bool, updateCols []string, rows ...Tset) (int64, error)
Uses the setional 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 Tset if no column is set in Tset (i.e. INSERT DEFAULT VALUES), then it upserts all NonPK columns
type TableQuery ¶ added in v0.15.0
type TableQuery[T any, Ts ~[]T, Tset any] struct { ViewQuery[T, Ts] // contains filtered or unexported fields }
func (*TableQuery[T, Tslice, Tset]) DeleteAll ¶ added in v0.15.0
func (t *TableQuery[T, Tslice, Tset]) DeleteAll() (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, Tset]) UpdateAll ¶ added in v0.15.0
func (t *TableQuery[T, Tslice, Tset]) UpdateAll(vals Tset) (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.15.0
type View[T any, Tslice ~[]T] struct { AfterSelectHooks orm.Hooks[T] // contains filtered or unexported fields }
func (*View[T, Tslice]) Name ¶ added in v0.15.0
func (v *View[T, Tslice]) Name(ctx context.Context) bob.Expression
func (*View[T, Tslice]) NameAs ¶ added in v0.15.0
func (v *View[T, Tslice]) NameAs(ctx context.Context) bob.Expression
func (*View[T, Tslice]) Prepare ¶ added in v0.15.0
func (v *View[T, Tslice]) Prepare(ctx context.Context, exec bob.Preparer, queryMods ...bob.Mod[*dialect.SelectQuery]) (bob.QueryStmt[T, Tslice], error)
Prepare a statement that will be mapped to the view's type
type ViewQuery ¶ added in v0.15.0
type ViewQuery[T any, Ts ~[]T] struct { bob.BaseQuery[*dialect.SelectQuery] // contains filtered or unexported fields }
func (*ViewQuery[T, Ts]) WriteQuery ¶ added in v0.15.0
type WhereMod ¶ added in v0.15.0
type WhereMod[Q Filterable, C any] struct { // contains filtered or unexported fields }
func Where ¶ added in v0.15.0
func Where[Q Filterable, C any](name Expression) WhereMod[Q, C]
type WhereNullMod ¶ added in v0.15.0
func WhereNull ¶ added in v0.15.0
func WhereNull[Q Filterable, C any](name Expression) WhereNullMod[Q, C]
func (WhereNullMod[Q, C]) IsNotNull ¶ added in v0.15.0
func (w WhereNullMod[Q, C]) IsNotNull() bob.Mod[Q]
func (WhereNullMod[Q, C]) IsNull ¶ added in v0.15.0
func (w WhereNullMod[Q, C]) IsNull() bob.Mod[Q]