Documentation
¶
Index ¶
- type Applier
- type Scope
- func In[T any](column string, values []T) Scope
- func Join(name string) Scope
- func LeftJoin(name string) Scope
- func Limit(n int) Scope
- func Offset(n int) Scope
- func OrderBy(clause string) Scope
- func Preload(name string) Scope
- func Select(columns ...string) Scope
- func Where(clause string, args ...any) Scope
- type Scopes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Applier ¶
type Applier interface {
ApplyWhere(clause string, args []any)
ApplyOrderBy(clause string)
ApplyLimit(n int)
ApplyOffset(n int)
ApplySelect(columns string)
ApplyJoin(name string)
ApplyLeftJoin(name string)
ApplyPreload(name string)
}
Applier is implemented by query builders to receive scope fragments. This interface lives in the scope package so that orm can import scope without creating circular dependencies.
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope represents a single query condition fragment. Scopes are immutable and safe to reuse across queries.
func In ¶
In returns a WHERE scope with an IN clause, expanding the slice into individual placeholders. No reflection is used; generics handle the type conversion.
scope.In("id", []int{1, 2, 3}) // → WHERE id IN (?, ?, ?)
func LeftJoin ¶ added in v0.0.15
LeftJoin returns a Scope that adds a LEFT JOIN for the named relation.
func OrderBy ¶
OrderBy returns a Scope that sets the ORDER BY clause.
scope.OrderBy("created_at DESC")
func Preload ¶ added in v0.0.15
Preload returns a Scope that registers a relation for eager loading.
func Select ¶
Select returns a Scope that overrides the SELECT column list.
scope.Select("id", "name")
type Scopes ¶
type Scopes []Scope
Scopes is a named slice of Scope, useful for conditionally building up a set of scopes.
var s scope.Scopes
if onlyActive {
s = s.Append(Active)
}
s = s.Append(Paginate(page, perPage))
Users(db).Scopes(s...).All(ctx)
func Combine ¶
Combine creates a Scopes from the given scopes.
scope.Combine(scope.Limit(10), scope.Offset(20))