selects

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 12 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingRelationship = fmt.Errorf("missing relationship")
	ErrMissingField        = fmt.Errorf("missing related field")
)

Functions

func InitializeRelationships

func InitializeRelationships(v any) error

func Load

func Load(tx builder.QueryExecer, v any, relation string) error

func LoadContext added in v0.11.4

func LoadContext(ctx context.Context, tx builder.QueryExecer, v any, relation string) error

func LoadMissing added in v0.14.0

func LoadMissing(tx builder.QueryExecer, v any, relation string) error

func LoadMissingContext added in v0.14.0

func LoadMissingContext(ctx context.Context, tx builder.QueryExecer, v any, relation string) error

func NewSelects

func NewSelects() *selects

Types

type BelongsTo

type BelongsTo[T models.Model] struct {
	// contains filtered or unexported fields
}

BelongsTo represents a belongs to relationship on a model. The parent model with a BelongsTo property will have a column referencing another tables primary key. For example if model Foo had a BelongsTo[*Bar] property the foos table would have a foos.bar_id column related to the bars.id column. Struct tags can be used to change the column names if they don't follow the default naming convention. The column on the parent model can be set with a foreign tag and the column on the related model can be set with an owner tag.

Tags:

  • owner: parent model
  • foreign: related model
Example
package main

import (
	"context"
	"fmt"

	"github.com/abibby/bob"
	"github.com/abibby/bob/dialects/sqlite"
	"github.com/abibby/bob/migrate"
	"github.com/abibby/bob/selects"
	"github.com/jmoiron/sqlx"
)

func main() {
	sqlite.UseSQLite()
	type Bar struct {
		bob.BaseModel
		ID   int    `db:"id,autoincrement,primary"`
		Name string `db:"name"`
	}

	type Foo struct {
		bob.BaseModel
		ID    int `db:"id,autoincrement,primary"`
		BarID int `db:"bar_id"`
		Bar   *selects.BelongsTo[*Bar]
	}

	db, _ := sqlx.Open("sqlite3", ":memory:")

	createFoo, _ := migrate.CreateFromModel(&Foo{})
	createFoo.Run(context.Background(), db)
	createBar, _ := migrate.CreateFromModel(&Bar{})
	createBar.Run(context.Background(), db)

	foo := &Foo{BarID: 1}
	bob.Save(db, foo)
	bar := &Bar{ID: 1, Name: "bar name"}
	bob.Save(db, bar)

	selects.Load(db, foo, "Bar")
	relatedBar, _ := foo.Bar.Value()

	fmt.Println(relatedBar.Name)

}
Output:

bar name

func (*BelongsTo[T]) ForeignKeys added in v0.16.5

func (r *BelongsTo[T]) ForeignKeys() []*ForeignKey

ForeignKeys returns a list of related tables and what columns they are related on.

func (*BelongsTo[T]) Initialize

func (r *BelongsTo[T]) Initialize(parent any, field reflect.StructField) error

func (*BelongsTo[T]) Load

func (r *BelongsTo[T]) Load(ctx context.Context, tx builder.QueryExecer, relations []Relationship) error

func (*BelongsTo) Loaded

func (v *BelongsTo) Loaded() bool

Loaded returns true if the relationship has been fetched and false if it has not.

func (*BelongsTo) MarshalJSON

func (v *BelongsTo) MarshalJSON() ([]byte, error)

func (BelongsTo) Subquery added in v0.7.0

func (r BelongsTo) Subquery() *SubBuilder

Subquery returns a SubBuilder scoped to the relationship.

func (*BelongsTo) Value

func (v *BelongsTo) Value() (T, bool)

Value will return the related value and if it has been fetched.

type Builder

type Builder[T models.Model] struct {
	// contains filtered or unexported fields
}

Builder represents an sql query and any bindings needed to run it.

func From

func From[T models.Model]() *Builder[T]

From creates a new query from the models table and with table.* selected

func New

func New[T models.Model]() *Builder[T]

New creates a new Builder with * selected

func NewEmpty

func NewEmpty[T models.Model]() *Builder[T]

NewEmpty creates a new builder without anything selected

func (*Builder[T]) AddGroupBy

func (b *Builder[T]) AddGroupBy(columns ...string) *Builder[T]

GroupBy adds a "group by" clause to the query.

func (*Builder[T]) AddSelect

func (b *Builder[T]) AddSelect(columns ...string) *Builder[T]

AddSelect adds new columns to be selected.

func (*Builder[T]) AddSelectFunction added in v0.4.1

func (b *Builder[T]) AddSelectFunction(function, column string) *Builder[T]

SelectFunction adds a column to be selected with a function applied.

func (*Builder[T]) AddSelectSubquery

func (b *Builder[T]) AddSelectSubquery(sb QueryBuilder, as string) *Builder[T]

AddSelectSubquery adds a subquery to be selected.

func (*Builder[T]) And

func (b *Builder[T]) And(cb func(q *Conditions)) *Builder[T]

And adds a group of conditions to the query

func (*Builder[T]) Clone added in v0.3.1

func (b *Builder[T]) Clone() *Builder[T]

func (*Builder[T]) Context added in v0.10.0

func (b *Builder[T]) Context() context.Context

Context returns the context value from the query.

func (*Builder[T]) CrossJoin added in v0.16.0

func (b *Builder[T]) CrossJoin(table, localColumn, operator, foreignColumn string) *Builder[T]

CrossJoin adds a cross join clause to the query.

func (*Builder[T]) CrossJoinOn added in v0.16.0

func (b *Builder[T]) CrossJoinOn(table string, cb func(q *Conditions)) *Builder[T]

CrossJoinOn adds a cross join clause to the query with a complex on statement.

func (*Builder[T]) Distinct

func (b *Builder[T]) Distinct() *Builder[T]

Distinct forces the query to only return distinct results.

func (*Builder[T]) Dump

func (b *Builder[T]) Dump() *Builder[T]

func (*Builder[T]) Find

func (b *Builder[T]) Find(tx builder.QueryExecer, primaryKeyValue any) (T, error)

Find returns the record with a matching primary key. It will fail on tables with multiple primary keys.

func (*Builder[T]) First

func (b *Builder[T]) First(tx builder.QueryExecer) (T, error)

Get executes the query as a select statement and returns the first record.

func (*Builder[T]) From

func (b *Builder[T]) From(table string) *Builder[T]

From sets the table which the query is targeting.

func (*Builder[T]) Get

func (b *Builder[T]) Get(tx builder.QueryExecer) ([]T, error)

Get executes the query as a select statement and returns the result.

func (*Builder[T]) GetTable added in v0.16.1

func (b *Builder[T]) GetTable() string

GetTable returns the table the query is targeting

func (*Builder[T]) GroupBy

func (b *Builder[T]) GroupBy(columns ...string) *Builder[T]

GroupBy sets the "group by" clause to the query.

func (*Builder[T]) Having

func (b *Builder[T]) Having(column, operator string, value any) *Builder[T]

Having adds a basic having clause to the query.

func (*Builder[T]) HavingAnd

func (b *Builder[T]) HavingAnd(cb func(q *Conditions)) *Builder[T]

HavingAnd adds a group of conditions to the query

func (*Builder[T]) HavingColumn added in v0.4.0

func (b *Builder[T]) HavingColumn(column, operator string, valueColumn string) *Builder[T]

HavingColumn adds a having clause to the query comparing two columns.

func (*Builder[T]) HavingExists added in v0.4.0

func (b *Builder[T]) HavingExists(query QueryBuilder) *Builder[T]

HavingExists add an exists clause to the query.

func (*Builder[T]) HavingHas added in v0.7.0

func (b *Builder[T]) HavingHas(relation string, cb func(q *SubBuilder) *SubBuilder) *Builder[T]

HavingHas adds a relationship exists condition to the query with having clauses.

func (*Builder[T]) HavingIn added in v0.4.0

func (b *Builder[T]) HavingIn(column string, values []any) *Builder[T]

HavingIn adds a having in clause to the query.

func (*Builder[T]) HavingOr

func (b *Builder[T]) HavingOr(cb func(q *Conditions)) *Builder[T]

HavingOr adds a group of conditions to the query with an or

func (*Builder[T]) HavingRaw added in v0.8.0

func (b *Builder[T]) HavingRaw(rawSql string, bindings ...any) *Builder[T]

HavingRaw adds a raw having clause to the query.

func (*Builder[T]) HavingSubquery added in v0.6.0

func (b *Builder[T]) HavingSubquery(subquery QueryBuilder, operator string, value any) *Builder[T]

HavingSubquery adds a having clause to the query comparing a column and a subquery.

func (*Builder[T]) InnerJoin added in v0.16.0

func (b *Builder[T]) InnerJoin(table, localColumn, operator, foreignColumn string) *Builder[T]

InnerJoin adds an inner join clause to the query.

func (*Builder[T]) InnerJoinOn added in v0.16.0

func (b *Builder[T]) InnerJoinOn(table string, cb func(q *Conditions)) *Builder[T]

InnerJoinOn adds an inner join clause to the query with a complex on statement.

func (*Builder[T]) Join

func (b *Builder[T]) Join(table, localColumn, operator, foreignColumn string) *Builder[T]

Join adds a join clause to the query.

func (*Builder[T]) JoinOn added in v0.16.0

func (b *Builder[T]) JoinOn(table string, cb func(q *Conditions)) *Builder[T]

JoinOn adds a join clause to the query with a complex on statement.

func (*Builder[T]) LeftJoin added in v0.16.0

func (b *Builder[T]) LeftJoin(table, localColumn, operator, foreignColumn string) *Builder[T]

LeftJoin adds a left join clause to the query.

func (*Builder[T]) LeftJoinOn added in v0.16.0

func (b *Builder[T]) LeftJoinOn(table string, cb func(q *Conditions)) *Builder[T]

LeftJoinOn adds a left join clause to the query with a complex on statement.

func (*Builder[T]) Limit

func (b *Builder[T]) Limit(limit int) *Builder[T]

Limit set the maximum number of rows to return.

func (*Builder[T]) Load added in v0.3.2

func (b *Builder[T]) Load(tx builder.QueryExecer, v any) error

Load executes the query as a select statement and sets v to the result.

func (*Builder[T]) LoadOne added in v0.3.2

func (b *Builder[T]) LoadOne(tx builder.QueryExecer, v any) error

Load executes the query as a select statement and sets v to the first record.

func (*Builder[T]) Offset

func (b *Builder[T]) Offset(offset int) *Builder[T]

Offset sets the number of rows to skip before returning the result.

func (*Builder[T]) Or

func (b *Builder[T]) Or(cb func(q *Conditions)) *Builder[T]

Or adds a group of conditions to the query with an or

func (*Builder[T]) OrHaving

func (b *Builder[T]) OrHaving(column, operator string, value any) *Builder[T]

OrHaving adds an or having clause to the query

func (*Builder[T]) OrHavingColumn added in v0.4.0

func (b *Builder[T]) OrHavingColumn(column, operator string, valueColumn string) *Builder[T]

OrHavingColumn adds an or having clause to the query comparing two columns.

func (*Builder[T]) OrHavingExists added in v0.4.0

func (b *Builder[T]) OrHavingExists(query QueryBuilder) *Builder[T]

WhereExists add an exists clause to the query.

func (*Builder[T]) OrHavingHas added in v0.7.0

func (b *Builder[T]) OrHavingHas(relation string, cb func(q *SubBuilder) *SubBuilder) *Builder[T]

OrHavingHas adds a relationship exists condition to the query with having clauses and an or.

func (*Builder[T]) OrHavingIn added in v0.4.0

func (b *Builder[T]) OrHavingIn(column string, values []any) *Builder[T]

OrHavingIn adds an or having in clause to the query.

func (*Builder[T]) OrHavingRaw added in v0.8.0

func (b *Builder[T]) OrHavingRaw(rawSql string, bindings ...any) *Builder[T]

OrHavingRaw adds a raw or having clause to the query.

func (*Builder[T]) OrHavingSubquery added in v0.6.0

func (b *Builder[T]) OrHavingSubquery(subquery QueryBuilder, operator string, value any) *Builder[T]

OrHavingSubquery adds an or having clause to the query comparing a column and a subquery.

func (*Builder[T]) OrWhere

func (b *Builder[T]) OrWhere(column, operator string, value any) *Builder[T]

OrWhere adds an or where clause to the query

func (*Builder[T]) OrWhereColumn

func (b *Builder[T]) OrWhereColumn(column, operator string, valueColumn string) *Builder[T]

OrWhereColumn adds an or where clause to the query comparing two columns.

func (*Builder[T]) OrWhereExists added in v0.4.0

func (b *Builder[T]) OrWhereExists(query QueryBuilder) *Builder[T]

WhereExists add an exists clause to the query.

func (*Builder[T]) OrWhereHas added in v0.7.0

func (b *Builder[T]) OrWhereHas(relation string, cb func(q *SubBuilder) *SubBuilder) *Builder[T]

OrWhereHas adds a relationship exists condition to the query with where clauses and an or.

func (*Builder[T]) OrWhereIn

func (b *Builder[T]) OrWhereIn(column string, values []any) *Builder[T]

OrWhereIn adds an or where in clause to the query.

func (*Builder[T]) OrWhereRaw added in v0.8.0

func (b *Builder[T]) OrWhereRaw(rawSql string, bindings ...any) *Builder[T]

OrWhereRaw adds a raw or where clause to the query.

func (*Builder[T]) OrWhereSubquery added in v0.6.0

func (b *Builder[T]) OrWhereSubquery(subquery QueryBuilder, operator string, value any) *Builder[T]

OrWhereSubquery adds an or where clause to the query comparing a column and a subquery.

func (*Builder[T]) OrderBy

func (b *Builder[T]) OrderBy(column string) *Builder[T]

OrderBy adds an order by clause to the query.

func (*Builder[T]) OrderByDesc added in v0.4.2

func (b *Builder[T]) OrderByDesc(column string) *Builder[T]

OrderByDesc adds a descending order by clause to the query.

func (*Builder[T]) RightJoin added in v0.16.0

func (b *Builder[T]) RightJoin(table, localColumn, operator, foreignColumn string) *Builder[T]

RightJoin adds a right join clause to the query.

func (*Builder[T]) RightJoinOn added in v0.16.0

func (b *Builder[T]) RightJoinOn(table string, cb func(q *Conditions)) *Builder[T]

RightJoinOn adds a right join clause to the query with a complex on statement.

func (*Builder[T]) Select

func (b *Builder[T]) Select(columns ...string) *Builder[T]

Select sets the columns to be selected.

func (*Builder[T]) SelectFunction added in v0.4.0

func (b *Builder[T]) SelectFunction(function, column string) *Builder[T]

SelectFunction sets a column to be selected with a function applied.

func (*Builder[T]) SelectSubquery

func (b *Builder[T]) SelectSubquery(sb QueryBuilder, as string) *Builder[T]

SelectSubquery sets a subquery to be selected.

func (*Builder[T]) ToSQL

func (b *Builder[T]) ToSQL(d dialects.Dialect) (string, []any, error)

func (*Builder[T]) Unordered added in v0.20.4

func (b *Builder[T]) Unordered() *Builder[T]

Unordered removes all order by clauses from the query.

func (*Builder[T]) Where

func (b *Builder[T]) Where(column, operator string, value any) *Builder[T]

Where adds a basic where clause to the query.

func (*Builder[T]) WhereColumn

func (b *Builder[T]) WhereColumn(column, operator string, valueColumn string) *Builder[T]

WhereColumn adds a where clause to the query comparing two columns.

func (*Builder[T]) WhereExists added in v0.4.0

func (b *Builder[T]) WhereExists(query QueryBuilder) *Builder[T]

WhereExists add an exists clause to the query.

func (*Builder[T]) WhereHas added in v0.7.0

func (b *Builder[T]) WhereHas(relation string, cb func(q *SubBuilder) *SubBuilder) *Builder[T]

WhereHas adds a relationship exists condition to the query with where clauses.

func (*Builder[T]) WhereIn

func (b *Builder[T]) WhereIn(column string, values []any) *Builder[T]

WhereIn adds a where in clause to the query.

func (*Builder[T]) WhereRaw added in v0.8.0

func (b *Builder[T]) WhereRaw(rawSql string, bindings ...any) *Builder[T]

WhereRaw adds a raw where clause to the query.

func (*Builder[T]) WhereSubquery added in v0.6.0

func (b *Builder[T]) WhereSubquery(subquery QueryBuilder, operator string, value any) *Builder[T]

WhereSubquery adds a where clause to the query comparing a column and a subquery.

func (*Builder[T]) With added in v0.5.0

func (b *Builder[T]) With(withs ...string) *Builder[T]

func (*Builder[T]) WithContext added in v0.10.0

func (b *Builder[T]) WithContext(ctx context.Context) *Builder[T]

WithContext adds a context to the query that will be used when fetching results.

func (*Builder[T]) WithScope added in v0.9.0

func (b *Builder[T]) WithScope(scope *Scope) *Builder[T]

WithScope adds a local scope to a query.

func (*Builder[T]) WithoutGlobalScope added in v0.9.1

func (b *Builder[T]) WithoutGlobalScope(scope *Scope) *Builder[T]

WithoutGlobalScope removes a global scope from the query.

func (*Builder[T]) WithoutScope added in v0.9.0

func (b *Builder[T]) WithoutScope(scope *Scope) *Builder[T]

WithoutScope removes the given scope from the local scopes.

type Conditions added in v0.16.0

type Conditions struct {
	// contains filtered or unexported fields
}

func (*Conditions) And added in v0.16.0

func (c *Conditions) And(cb func(q *Conditions)) *Conditions

And adds a group of conditions to the query

func (*Conditions) Clone added in v0.16.0

func (c *Conditions) Clone() *Conditions

func (*Conditions) Or added in v0.16.0

func (c *Conditions) Or(cb func(q *Conditions)) *Conditions

Or adds a group of conditions to the query with an or

func (*Conditions) OrWhere added in v0.16.0

func (c *Conditions) OrWhere(column, operator string, value any) *Conditions

OrWhere adds an or where clause to the query

func (*Conditions) OrWhereColumn added in v0.16.0

func (c *Conditions) OrWhereColumn(column, operator string, valueColumn string) *Conditions

OrWhereColumn adds an or where clause to the query comparing two columns.

func (*Conditions) OrWhereExists added in v0.16.0

func (c *Conditions) OrWhereExists(query QueryBuilder) *Conditions

WhereExists add an exists clause to the query.

func (*Conditions) OrWhereHas added in v0.16.0

func (c *Conditions) OrWhereHas(relation string, cb func(q *SubBuilder) *SubBuilder) *Conditions

OrWhereHas adds a relationship exists condition to the query with where clauses and an or.

func (*Conditions) OrWhereIn added in v0.16.0

func (c *Conditions) OrWhereIn(column string, values []any) *Conditions

OrWhereIn adds an or where in clause to the query.

func (*Conditions) OrWhereRaw added in v0.16.0

func (c *Conditions) OrWhereRaw(rawSql string, bindings ...any) *Conditions

OrWhereRaw adds a raw or where clause to the query.

func (*Conditions) OrWhereSubquery added in v0.16.0

func (c *Conditions) OrWhereSubquery(subquery QueryBuilder, operator string, value any) *Conditions

OrWhereSubquery adds an or where clause to the query comparing a column and a subquery.

func (*Conditions) ToSQL added in v0.16.0

func (c *Conditions) ToSQL(d dialects.Dialect) (string, []any, error)

func (*Conditions) Where added in v0.16.0

func (c *Conditions) Where(column, operator string, value any) *Conditions

Where adds a basic where clause to the query.

func (*Conditions) WhereColumn added in v0.16.0

func (c *Conditions) WhereColumn(column, operator string, valueColumn string) *Conditions

WhereColumn adds a where clause to the query comparing two columns.

func (*Conditions) WhereExists added in v0.16.0

func (c *Conditions) WhereExists(query QueryBuilder) *Conditions

WhereExists add an exists clause to the query.

func (*Conditions) WhereHas added in v0.16.0

func (c *Conditions) WhereHas(relation string, cb func(q *SubBuilder) *SubBuilder) *Conditions

WhereHas adds a relationship exists condition to the query with where clauses.

func (*Conditions) WhereIn added in v0.16.0

func (c *Conditions) WhereIn(column string, values []any) *Conditions

WhereIn adds a where in clause to the query.

func (*Conditions) WhereRaw added in v0.16.0

func (c *Conditions) WhereRaw(rawSql string, bindings ...any) *Conditions

WhereRaw adds a raw where clause to the query.

func (*Conditions) WhereSubquery added in v0.16.0

func (c *Conditions) WhereSubquery(subquery QueryBuilder, operator string, value any) *Conditions

WhereSubquery adds a where clause to the query comparing a column and a subquery.

type ForeignKey added in v0.16.5

type ForeignKey struct {
	LocalKey     string
	RelatedTable string
	RelatedKey   string
}

func (*ForeignKey) Equal added in v0.16.5

func (f *ForeignKey) Equal(v *ForeignKey) bool

type HasMany

type HasMany[T models.Model] struct {
	// contains filtered or unexported fields
}

Tags:

  • local: parent model
  • foreign: related model

func (*HasMany[T]) ForeignKeys added in v0.16.5

func (r *HasMany[T]) ForeignKeys() []*ForeignKey

ForeignKeys returns a list of related tables and what columns they are related on.

func (*HasMany[T]) Initialize

func (r *HasMany[T]) Initialize(parent any, field reflect.StructField) error

func (*HasMany[T]) Load

func (r *HasMany[T]) Load(ctx context.Context, tx builder.QueryExecer, relations []Relationship) error

func (*HasMany) Loaded

func (v *HasMany) Loaded() bool

Loaded returns true if the relationship has been fetched and false if it has not.

func (*HasMany) MarshalJSON

func (v *HasMany) MarshalJSON() ([]byte, error)

func (HasMany) Subquery added in v0.7.0

func (r HasMany) Subquery() *SubBuilder

Subquery returns a SubBuilder scoped to the relationship.

func (*HasMany) Value

func (v *HasMany) Value() (T, bool)

Value will return the related value and if it has been fetched.

type HasOne

type HasOne[T models.Model] struct {
	// contains filtered or unexported fields
}

Tags:

  • local: parent model
  • foreign: related model

func (*HasOne[T]) ForeignKeys added in v0.16.5

func (r *HasOne[T]) ForeignKeys() []*ForeignKey

ForeignKeys returns a list of related tables and what columns they are related on.

func (*HasOne[T]) Initialize

func (r *HasOne[T]) Initialize(parent any, field reflect.StructField) error

func (*HasOne[T]) Load

func (r *HasOne[T]) Load(ctx context.Context, tx builder.QueryExecer, relations []Relationship) error

func (*HasOne) Loaded

func (v *HasOne) Loaded() bool

Loaded returns true if the relationship has been fetched and false if it has not.

func (*HasOne) MarshalJSON

func (v *HasOne) MarshalJSON() ([]byte, error)

func (HasOne) Subquery added in v0.7.0

func (r HasOne) Subquery() *SubBuilder

Subquery returns a SubBuilder scoped to the relationship.

func (*HasOne) Value

func (v *HasOne) Value() (T, bool)

Value will return the related value and if it has been fetched.

type QueryBuilder added in v0.4.1

type QueryBuilder interface {
	builder.ToSQLer
	// contains filtered or unexported methods
}

QueryBuilder is implemented by *Builder and *SubBuilder

type Relationship

type Relationship interface {
	Subquery() *SubBuilder
	Initialize(self any, field reflect.StructField) error
	Load(ctx context.Context, tx builder.QueryExecer, relations []Relationship) error
	Loaded() bool
	ForeignKeys() []*ForeignKey
}

type Scope added in v0.9.0

type Scope struct {
	Name  string
	Apply ScopeFunc
}

Scope is a modifier for a query that can be easily applied.

type ScopeFunc added in v0.9.0

type ScopeFunc func(b *SubBuilder) *SubBuilder

type Scoper added in v0.9.1

type Scoper interface {
	Scopes() []*Scope
}

type SubBuilder added in v0.7.0

type SubBuilder struct {
	// contains filtered or unexported fields
}

func NewSubBuilder added in v0.7.0

func NewSubBuilder() *SubBuilder

NewSubBuilder creates a new SubBuilder without anything selected

func (*SubBuilder) AddGroupBy added in v0.7.0

func (b *SubBuilder) AddGroupBy(columns ...string) *SubBuilder

GroupBy adds a "group by" clause to the query.

func (*SubBuilder) AddSelect added in v0.7.0

func (b *SubBuilder) AddSelect(columns ...string) *SubBuilder

AddSelect adds new columns to be selected.

func (*SubBuilder) AddSelectFunction added in v0.7.0

func (b *SubBuilder) AddSelectFunction(function, column string) *SubBuilder

SelectFunction adds a column to be selected with a function applied.

func (*SubBuilder) AddSelectSubquery added in v0.7.0

func (b *SubBuilder) AddSelectSubquery(sb QueryBuilder, as string) *SubBuilder

AddSelectSubquery adds a subquery to be selected.

func (*SubBuilder) And added in v0.7.0

func (b *SubBuilder) And(cb func(q *Conditions)) *SubBuilder

And adds a group of conditions to the query

func (*SubBuilder) Clone added in v0.7.0

func (b *SubBuilder) Clone() *SubBuilder

func (*SubBuilder) Context added in v0.10.0

func (b *SubBuilder) Context() context.Context

Context returns the context value from the query.

func (*SubBuilder) CrossJoin added in v0.16.0

func (b *SubBuilder) CrossJoin(table, localColumn, operator, foreignColumn string) *SubBuilder

CrossJoin adds a cross join clause to the query.

func (*SubBuilder) CrossJoinOn added in v0.16.0

func (b *SubBuilder) CrossJoinOn(table string, cb func(q *Conditions)) *SubBuilder

CrossJoinOn adds a cross join clause to the query with a complex on statement.

func (*SubBuilder) Distinct added in v0.7.0

func (b *SubBuilder) Distinct() *SubBuilder

Distinct forces the query to only return distinct results.

func (*SubBuilder) Dump added in v0.7.0

func (b *SubBuilder) Dump() *SubBuilder

func (*SubBuilder) From added in v0.7.0

func (b *SubBuilder) From(table string) *SubBuilder

From sets the table which the query is targeting.

func (*SubBuilder) GetTable added in v0.16.1

func (b *SubBuilder) GetTable() string

GetTable returns the table the query is targeting

func (*SubBuilder) GroupBy added in v0.7.0

func (b *SubBuilder) GroupBy(columns ...string) *SubBuilder

GroupBy sets the "group by" clause to the query.

func (*SubBuilder) Having added in v0.7.0

func (b *SubBuilder) Having(column, operator string, value any) *SubBuilder

Having adds a basic having clause to the query.

func (*SubBuilder) HavingAnd added in v0.7.0

func (b *SubBuilder) HavingAnd(cb func(q *Conditions)) *SubBuilder

HavingAnd adds a group of conditions to the query

func (*SubBuilder) HavingColumn added in v0.7.0

func (b *SubBuilder) HavingColumn(column, operator string, valueColumn string) *SubBuilder

HavingColumn adds a having clause to the query comparing two columns.

func (*SubBuilder) HavingExists added in v0.7.0

func (b *SubBuilder) HavingExists(query QueryBuilder) *SubBuilder

HavingExists add an exists clause to the query.

func (*SubBuilder) HavingHas added in v0.7.0

func (b *SubBuilder) HavingHas(relation string, cb func(q *SubBuilder) *SubBuilder) *SubBuilder

HavingHas adds a relationship exists condition to the query with having clauses.

func (*SubBuilder) HavingIn added in v0.7.0

func (b *SubBuilder) HavingIn(column string, values []any) *SubBuilder

HavingIn adds a having in clause to the query.

func (*SubBuilder) HavingOr added in v0.7.0

func (b *SubBuilder) HavingOr(cb func(q *Conditions)) *SubBuilder

HavingOr adds a group of conditions to the query with an or

func (*SubBuilder) HavingRaw added in v0.8.0

func (b *SubBuilder) HavingRaw(rawSql string, bindings ...any) *SubBuilder

HavingRaw adds a raw having clause to the query.

func (*SubBuilder) HavingSubquery added in v0.7.0

func (b *SubBuilder) HavingSubquery(subquery QueryBuilder, operator string, value any) *SubBuilder

HavingSubquery adds a having clause to the query comparing a column and a subquery.

func (*SubBuilder) InnerJoin added in v0.16.0

func (b *SubBuilder) InnerJoin(table, localColumn, operator, foreignColumn string) *SubBuilder

InnerJoin adds an inner join clause to the query.

func (*SubBuilder) InnerJoinOn added in v0.16.0

func (b *SubBuilder) InnerJoinOn(table string, cb func(q *Conditions)) *SubBuilder

InnerJoinOn adds an inner join clause to the query with a complex on statement.

func (*SubBuilder) Join added in v0.16.0

func (b *SubBuilder) Join(table, localColumn, operator, foreignColumn string) *SubBuilder

Join adds a join clause to the query.

func (*SubBuilder) JoinOn added in v0.16.0

func (b *SubBuilder) JoinOn(table string, cb func(q *Conditions)) *SubBuilder

JoinOn adds a join clause to the query with a complex on statement.

func (*SubBuilder) LeftJoin added in v0.16.0

func (b *SubBuilder) LeftJoin(table, localColumn, operator, foreignColumn string) *SubBuilder

LeftJoin adds a left join clause to the query.

func (*SubBuilder) LeftJoinOn added in v0.16.0

func (b *SubBuilder) LeftJoinOn(table string, cb func(q *Conditions)) *SubBuilder

LeftJoinOn adds a left join clause to the query with a complex on statement.

func (*SubBuilder) Limit added in v0.7.0

func (b *SubBuilder) Limit(limit int) *SubBuilder

Limit set the maximum number of rows to return.

func (*SubBuilder) Offset added in v0.7.0

func (b *SubBuilder) Offset(offset int) *SubBuilder

Offset sets the number of rows to skip before returning the result.

func (*SubBuilder) Or added in v0.7.0

func (b *SubBuilder) Or(cb func(q *Conditions)) *SubBuilder

Or adds a group of conditions to the query with an or

func (*SubBuilder) OrHaving added in v0.7.0

func (b *SubBuilder) OrHaving(column, operator string, value any) *SubBuilder

OrHaving adds an or having clause to the query

func (*SubBuilder) OrHavingColumn added in v0.7.0

func (b *SubBuilder) OrHavingColumn(column, operator string, valueColumn string) *SubBuilder

OrHavingColumn adds an or having clause to the query comparing two columns.

func (*SubBuilder) OrHavingExists added in v0.7.0

func (b *SubBuilder) OrHavingExists(query QueryBuilder) *SubBuilder

WhereExists add an exists clause to the query.

func (*SubBuilder) OrHavingHas added in v0.7.0

func (b *SubBuilder) OrHavingHas(relation string, cb func(q *SubBuilder) *SubBuilder) *SubBuilder

OrHavingHas adds a relationship exists condition to the query with having clauses and an or.

func (*SubBuilder) OrHavingIn added in v0.7.0

func (b *SubBuilder) OrHavingIn(column string, values []any) *SubBuilder

OrHavingIn adds an or having in clause to the query.

func (*SubBuilder) OrHavingRaw added in v0.8.0

func (b *SubBuilder) OrHavingRaw(rawSql string, bindings ...any) *SubBuilder

OrHavingRaw adds a raw or having clause to the query.

func (*SubBuilder) OrHavingSubquery added in v0.7.0

func (b *SubBuilder) OrHavingSubquery(subquery QueryBuilder, operator string, value any) *SubBuilder

OrHavingSubquery adds an or having clause to the query comparing a column and a subquery.

func (*SubBuilder) OrWhere added in v0.7.0

func (b *SubBuilder) OrWhere(column, operator string, value any) *SubBuilder

OrWhere adds an or where clause to the query

func (*SubBuilder) OrWhereColumn added in v0.7.0

func (b *SubBuilder) OrWhereColumn(column, operator string, valueColumn string) *SubBuilder

OrWhereColumn adds an or where clause to the query comparing two columns.

func (*SubBuilder) OrWhereExists added in v0.7.0

func (b *SubBuilder) OrWhereExists(query QueryBuilder) *SubBuilder

WhereExists add an exists clause to the query.

func (*SubBuilder) OrWhereHas added in v0.7.0

func (b *SubBuilder) OrWhereHas(relation string, cb func(q *SubBuilder) *SubBuilder) *SubBuilder

OrWhereHas adds a relationship exists condition to the query with where clauses and an or.

func (*SubBuilder) OrWhereIn added in v0.7.0

func (b *SubBuilder) OrWhereIn(column string, values []any) *SubBuilder

OrWhereIn adds an or where in clause to the query.

func (*SubBuilder) OrWhereRaw added in v0.8.0

func (b *SubBuilder) OrWhereRaw(rawSql string, bindings ...any) *SubBuilder

OrWhereRaw adds a raw or where clause to the query.

func (*SubBuilder) OrWhereSubquery added in v0.7.0

func (b *SubBuilder) OrWhereSubquery(subquery QueryBuilder, operator string, value any) *SubBuilder

OrWhereSubquery adds an or where clause to the query comparing a column and a subquery.

func (*SubBuilder) OrderBy added in v0.7.0

func (b *SubBuilder) OrderBy(column string) *SubBuilder

OrderBy adds an order by clause to the query.

func (*SubBuilder) OrderByDesc added in v0.7.0

func (b *SubBuilder) OrderByDesc(column string) *SubBuilder

OrderByDesc adds a descending order by clause to the query.

func (*SubBuilder) RightJoin added in v0.16.0

func (b *SubBuilder) RightJoin(table, localColumn, operator, foreignColumn string) *SubBuilder

RightJoin adds a right join clause to the query.

func (*SubBuilder) RightJoinOn added in v0.16.0

func (b *SubBuilder) RightJoinOn(table string, cb func(q *Conditions)) *SubBuilder

RightJoinOn adds a right join clause to the query with a complex on statement.

func (*SubBuilder) Select added in v0.7.0

func (b *SubBuilder) Select(columns ...string) *SubBuilder

Select sets the columns to be selected.

func (*SubBuilder) SelectFunction added in v0.7.0

func (b *SubBuilder) SelectFunction(function, column string) *SubBuilder

SelectFunction sets a column to be selected with a function applied.

func (*SubBuilder) SelectSubquery added in v0.7.0

func (b *SubBuilder) SelectSubquery(sb QueryBuilder, as string) *SubBuilder

SelectSubquery sets a subquery to be selected.

func (*SubBuilder) ToSQL added in v0.7.0

func (b *SubBuilder) ToSQL(d dialects.Dialect) (string, []any, error)

func (*SubBuilder) Unordered added in v0.20.4

func (b *SubBuilder) Unordered() *SubBuilder

Unordered removes all order by clauses from the query.

func (*SubBuilder) Where added in v0.7.0

func (b *SubBuilder) Where(column, operator string, value any) *SubBuilder

Where adds a basic where clause to the query.

func (*SubBuilder) WhereColumn added in v0.7.0

func (b *SubBuilder) WhereColumn(column, operator string, valueColumn string) *SubBuilder

WhereColumn adds a where clause to the query comparing two columns.

func (*SubBuilder) WhereExists added in v0.7.0

func (b *SubBuilder) WhereExists(query QueryBuilder) *SubBuilder

WhereExists add an exists clause to the query.

func (*SubBuilder) WhereHas added in v0.7.0

func (b *SubBuilder) WhereHas(relation string, cb func(q *SubBuilder) *SubBuilder) *SubBuilder

WhereHas adds a relationship exists condition to the query with where clauses.

func (*SubBuilder) WhereIn added in v0.7.0

func (b *SubBuilder) WhereIn(column string, values []any) *SubBuilder

WhereIn adds a where in clause to the query.

func (*SubBuilder) WhereRaw added in v0.8.0

func (b *SubBuilder) WhereRaw(rawSql string, bindings ...any) *SubBuilder

WhereRaw adds a raw where clause to the query.

func (*SubBuilder) WhereSubquery added in v0.7.0

func (b *SubBuilder) WhereSubquery(subquery QueryBuilder, operator string, value any) *SubBuilder

WhereSubquery adds a where clause to the query comparing a column and a subquery.

func (*SubBuilder) WithContext added in v0.10.0

func (b *SubBuilder) WithContext(ctx context.Context) *SubBuilder

WithContext adds a context to the query that will be used when fetching results.

func (*SubBuilder) WithScope added in v0.9.0

func (b *SubBuilder) WithScope(scope *Scope) *SubBuilder

WithScope adds a local scope to a query.

func (*SubBuilder) WithoutGlobalScope added in v0.9.3

func (b *SubBuilder) WithoutGlobalScope(scope *Scope) *SubBuilder

WithoutGlobalScope removes a global scope from the query.

func (*SubBuilder) WithoutScope added in v0.9.0

func (b *SubBuilder) WithoutScope(scope *Scope) *SubBuilder

WithoutScope removes the given scope from the local scopes.

Jump to

Keyboard shortcuts

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