Documentation
¶
Overview ¶
Package query is a type-safe builder for package ast. It does not produce SQL text.
Index ¶
- Constants
- Variables
- type AggOption
- type Aliased
- type AnyExpr
- type AnySet
- type BoundSet
- type CaseSearched
- type CaseSimple
- type CastType
- type Comparable
- type CountArg
- type Expr
- func Bind[T Scalar](v T) Expr[T]
- func Cast[To Scalar](e AnyExpr, t CastType) Expr[To]
- func Coalesce[T Scalar](es ...Expr[T]) Expr[T]
- func Count(e CountArg, opts ...AggOption) Expr[int64]
- func JSONArray(es ...AnyExpr) Expr[[]byte]
- func JSONObject(pairs ...JSONPair) Expr[[]byte]
- func Lit[T Literal](v T) Expr[T]
- func Lower(e Expr[string]) Expr[string]
- func ScalarExpr[T Scalar](s *Statement) Expr[T]
- func Upper(e Expr[string]) Expr[string]
- type JSONPair
- type JoinType
- type Literal
- type Op
- type OrderTerm
- type Ordered
- type Predicate
- func And(p Predicate, ps ...Predicate) Predicate
- func Between[T Ordered](a, lo, hi Expr[T]) Predicate
- func Compare[T Ordered](op Op, a, b Expr[T]) Predicate
- func Eq[T Comparable](a, b Expr[T]) Predicate
- func Exists(s *Statement) Predicate
- func False() Predicate
- func Gt[T Ordered](a, b Expr[T]) Predicate
- func Gte[T Ordered](a, b Expr[T]) Predicate
- func In[T Comparable](a Expr[T], vs ...Expr[T]) Predicate
- func IsNull[T Scalar](a Expr[T]) Predicate
- func Like(a, pattern Expr[string]) Predicate
- func Lt[T Ordered](a, b Expr[T]) Predicate
- func Lte[T Ordered](a, b Expr[T]) Predicate
- func Ne[T Comparable](a, b Expr[T]) Predicate
- func Not(p Predicate) Predicate
- func Or(p Predicate, ps ...Predicate) Predicate
- func Quantified[T Comparable](a Expr[T], op Op, q Quantifier, set AnySet[T]) Predicate
- func True() Predicate
- type Projection
- type Quantifier
- type Scalar
- type SetExpr
- type SortDirection
- type Statement
- func (s *Statement) Columns(cols ...Projection) *Statement
- func (s *Statement) CrossJoin(t Tuple) *Statement
- func (s *Statement) Distinct() *Statement
- func (s *Statement) From(ts ...Tuple) *Statement
- func (s *Statement) GroupBy(es ...AnyExpr) *Statement
- func (s *Statement) Having(p Predicate) *Statement
- func (s *Statement) Join(t Tuple, on Predicate) *Statement
- func (s *Statement) JoinOn(jt JoinType, t Tuple, on Predicate) *Statement
- func (s *Statement) Limit(n uint64) *Statement
- func (s *Statement) Offset(n uint64) *Statement
- func (s *Statement) OrderBy(terms ...OrderTerm) *Statement
- func (s *Statement) Where(p Predicate) *Statement
- type SubjectKinds
- type Tuple
- func (t Tuple) Condition() Expr[string]
- func (t Tuple) ConditionContext() Expr[[]byte]
- func (t Tuple) ObjectID() Expr[string]
- func (t Tuple) ObjectRelation() Expr[string]
- func (t Tuple) ObjectType() Expr[string]
- func (t Tuple) Store() Expr[string]
- func (t Tuple) SubjectID() Expr[string]
- func (t Tuple) SubjectKindIn(kinds SubjectKinds) Predicate
- func (t Tuple) SubjectRelation() Expr[string]
- func (t Tuple) SubjectType() Expr[string]
Constants ¶
const ( OpEq = ast.OpEq OpNe = ast.OpNe OpLt = ast.OpLt OpLte = ast.OpLte OpGt = ast.OpGt OpGte = ast.OpGte Any = ast.Any All = ast.All JoinInner = ast.JoinInner JoinLeftOuter = ast.JoinLeftOuter JoinCross = ast.JoinCross Ascending = ast.Ascending Descending = ast.Descending TypeVarchar = ast.TypeVarchar TypeInteger = ast.TypeInteger TypeBigint = ast.TypeBigint TypeNumeric = ast.TypeNumeric TypeVarbinary = ast.TypeVarbinary KindUser = ast.KindUser KindUserset = ast.KindUserset KindAll = ast.KindAll )
Variables ¶
var AggDistinct = AggOption{/* contains filtered or unexported fields */}
AggDistinct makes Count(x, AggDistinct) COUNT(DISTINCT x).
var Star starArg
Star makes Count(Star) COUNT(*).
Functions ¶
This section is empty.
Types ¶
type AggOption ¶
type AggOption struct {
// contains filtered or unexported fields
}
AggOption is AggDistinct or AggFilter.
type Aliased ¶
type Aliased struct {
// contains filtered or unexported fields
}
Aliased is a named result column.
type AnyExpr ¶
type AnyExpr interface {
// contains filtered or unexported methods
}
AnyExpr is an Expr of any T.
type AnySet ¶
type AnySet[T Scalar] interface { // contains filtered or unexported methods }
AnySet is a BoundSet or SetExpr. Elem is never called; it only ties the set to T.
type BoundSet ¶
type BoundSet[T Scalar] struct { // contains filtered or unexported fields }
BoundSet is a list of T values sent as one parameter, for use with Quantified.
type CaseSearched ¶
type CaseSearched[T Scalar] struct { // contains filtered or unexported fields }
CaseSearched builds "CASE WHEN cond THEN ... END". Start one with Case:
query.Case[string]().
When(query.Eq(t.ObjectType(), query.Lit("folder")), t.ObjectID()).
Else(query.Lit("")).
End()
func Case ¶
func Case[T Scalar]() *CaseSearched[T]
func (*CaseSearched[T]) Else ¶
func (c *CaseSearched[T]) Else(result Expr[T]) *CaseSearched[T]
Else replaces any earlier Else.
func (*CaseSearched[T]) End ¶
func (c *CaseSearched[T]) End() Expr[T]
End panics if there are no branches.
func (*CaseSearched[T]) When ¶
func (c *CaseSearched[T]) When(cond Predicate, then Expr[T]) *CaseSearched[T]
type CaseSimple ¶
type CaseSimple[T Scalar, B Comparable] struct { // contains filtered or unexported fields }
CaseSimple builds "CASE base WHEN value THEN ... END". Start one with CaseOf:
query.CaseOf[int64](t.ObjectType()).
When(query.Lit("folder"), query.Lit[int64](1)).
Else(query.Lit[int64](0)).
End()
func CaseOf ¶
func CaseOf[T Scalar, B Comparable](base Expr[B]) *CaseSimple[T, B]
func (*CaseSimple[T, B]) Else ¶
func (c *CaseSimple[T, B]) Else(result Expr[T]) *CaseSimple[T, B]
Else replaces any earlier Else.
func (*CaseSimple[T, B]) End ¶
func (c *CaseSimple[T, B]) End() Expr[T]
End panics if there are no branches.
func (*CaseSimple[T, B]) When ¶
func (c *CaseSimple[T, B]) When(value Expr[B], then Expr[T]) *CaseSimple[T, B]
type Comparable ¶
type Comparable interface {
Scalar
comparable
}
Comparable is Scalar without []byte.
type CountArg ¶
type CountArg interface {
// contains filtered or unexported methods
}
CountArg is any Expr, or Star.
type Expr ¶
type Expr[T Scalar] struct { // contains filtered or unexported fields }
Expr is a SQL value of Go type T.
func JSONObject ¶
func ScalarExpr ¶
ScalarExpr uses a single-value subquery as an Expr.
type JSONPair ¶
type JSONPair struct {
// contains filtered or unexported fields
}
JSONPair is one key/value pair for JSONObject.
type Literal ¶
type Literal interface {
// contains filtered or unexported methods
}
Literal excludes time.Time, whose literal syntax differs by database.
type OrderTerm ¶
type OrderTerm struct {
// contains filtered or unexported fields
}
OrderTerm is one ORDER BY term.
func Order ¶
func Order(e AnyExpr, dir SortDirection) OrderTerm
type Predicate ¶
type Predicate struct {
// contains filtered or unexported fields
}
Predicate is a true/false expression. It is not an Expr[bool] because some databases have no boolean type, so it cannot be a value or result column.
func Eq ¶
func Eq[T Comparable](a, b Expr[T]) Predicate
func In ¶
func In[T Comparable](a Expr[T], vs ...Expr[T]) Predicate
In is "a IN (vs...)". For a list parameter or subquery, use Quantified.
func Ne ¶
func Ne[T Comparable](a, b Expr[T]) Predicate
func Quantified ¶
func Quantified[T Comparable](a Expr[T], op Op, q Quantifier, set AnySet[T]) Predicate
Quantified is "a op ANY (set)" or "a op ALL (set)".
type Projection ¶
type Projection interface {
// contains filtered or unexported methods
}
Projection is anything that can go in a SELECT list.
type Quantifier ¶
type Quantifier = ast.Quantifier
type Scalar ¶
Scalar follows database/sql/driver.Value, minus bool (use Predicate). Time.Time has no ~ because drivers reject named struct types.
type SetExpr ¶
type SetExpr[T Scalar] struct { // contains filtered or unexported fields }
SetExpr is a multi-row subquery of T values.
func SetSubExpr ¶
SetSubExpr uses a multi-row subquery as a SetExpr.
type SortDirection ¶
type SortDirection = ast.SortDirection
type Statement ¶
Statement builds an ast.Select. Where, Having, Limit, and Offset replace earlier values; other methods append.
func Select ¶
func Select(cols ...Projection) *Statement
func (*Statement) Columns ¶
func (s *Statement) Columns(cols ...Projection) *Statement
type SubjectKinds ¶
type SubjectKinds = ast.SubjectKinds
type Tuple ¶
type Tuple struct {
// contains filtered or unexported fields
}
Tuple is the tuple table under an alias. Its methods return columns qualified by that alias.
func (Tuple) ConditionContext ¶
ConditionContext is a proto-encoded structpb.Struct.
func (Tuple) ObjectRelation ¶
func (Tuple) ObjectType ¶
func (Tuple) SubjectKindIn ¶
func (t Tuple) SubjectKindIn(kinds SubjectKinds) Predicate
SubjectKindIn is true when the subject is one of kinds.
func (Tuple) SubjectRelation ¶
SubjectRelation is e.g. `member` in `group:eng#member`. It is also empty for wildcards like `user:*`, so empty does not imply a non-userset subject.