Documentation
¶
Index ¶
- Constants
- type ConstantQueryTerm
- type FunctionCallQueryTerm
- type InjectedQueryTerm
- type MultiQueryTerm
- type Query
- func (query *Query[T]) From(table string) *Query[T]
- func (query *Query[T]) FromQuery(inner *Query[T]) *Query[T]
- func (query *Query[T]) GroupBy(fields ...string) *Query[T]
- func (query *Query[T]) Limit(limit uint) *Query[T]
- func (query *Query[T]) Offset(offset uint) *Query[T]
- func (query *Query[T]) OrderBy(fields ...string) *Query[T]
- func (query *Query[T]) Run(ctx context.Context, db *sql.DB) ([]*T, error)
- func (query *Query[T]) Select(fields ...string) *Query[T]
- func (query *Query[T]) String() string
- func (query *Query[T]) Where(op string, clauses ...WhereClause[T]) *Query[T]
- type WhereClause
Constants ¶
const ( And = "AND" Or = "OR" )
Constant Boolean connection operations
const ( Equals = "=" NotEqual = "<>" GreaterThan = ">" GreaterThanEqualTo = ">=" LessThan = "<" LessThanEqualTo = "<=" Like = "LIKE" )
Constant comparison operations
const (
All = "*"
)
SQL constants
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConstantQueryTerm ¶
ConstantQueryTerm contains the functionality allowing the user to compare a database field to a concrete value
func NewConstantQueryTerm ¶
func NewConstantQueryTerm[T any](name string, op string, value string) *ConstantQueryTerm[T]
NewConstantQueryTerm creates a new constant query term from the field name, the comparison operation and a value to which the field should be compared
func (*ConstantQueryTerm[T]) ModifyQuery ¶
func (term *ConstantQueryTerm[T]) ModifyQuery(query *Query[T])
ModifyQuery modifies the query to include this query term
type FunctionCallQueryTerm ¶ added in v1.1.43
FunctionCallQueryTerm creates a new function call query term that allows the user to inject an SQL function call into the WHERE clause of an SQL query
func NewFunctionCallQueryTerm ¶ added in v1.1.43
func NewFunctionCallQueryTerm[T any](call string, args ...any) *FunctionCallQueryTerm[T]
NewFunctionCallQueryTerm creates a new function call query term from a function name and arguments
func (*FunctionCallQueryTerm[T]) ModifyQuery ¶ added in v1.1.43
func (term *FunctionCallQueryTerm[T]) ModifyQuery(query *Query[T])
ModifyQuery modifies the query to include this query term
type InjectedQueryTerm ¶
InjectedQueryTerm creates a new query term that injects an argument into the query's arguments list and a placeholder ? into the query string itself. This is intended for variables that need to be added to SQL queries, thereby avoiding the possibility of SQL injection
func NewInjectedQueryTerm ¶
func NewInjectedQueryTerm[T any](name string, op string, value any) *InjectedQueryTerm[T]
NewInjectedQueryTerm creates a new injected query term from a field name, a comparison operation, and a value to which the field should be compared, to be injected later
func (*InjectedQueryTerm[T]) ModifyQuery ¶
func (term *InjectedQueryTerm[T]) ModifyQuery(query *Query[T])
ModifyQuery modifies the query to include this query term
type MultiQueryTerm ¶
type MultiQueryTerm[T any] struct { Operator string Inner []WhereClause[T] }
MultiQueryTerm creates a new query term that allows multiple query terms to be joined together inside a set of parentheses. This is intended to allow for alternating sets of AND/OR logic (i.e. A AND (B OR C))
func NewMultiQueryTerm ¶
func NewMultiQueryTerm[T any](op string, terms ...WhereClause[T]) *MultiQueryTerm[T]
NewMultiQueryTerm creates a new multi-query term from a connecting operator and a list of inner terms
func (*MultiQueryTerm[T]) ModifyQuery ¶
func (term *MultiQueryTerm[T]) ModifyQuery(query *Query[T])
ModifyQuery modifies the query to include this query term
type Query ¶
type Query[T any] struct { // contains filtered or unexported fields }
Query allows for the creation of execution of SQL queries in a programmatic manner
func (*Query[T]) From ¶
From sets the table that data should be pulled from, returning the modified query so that this function can be chained with others
func (*Query[T]) FromQuery ¶ added in v1.1.46
FromQuery sets the table that the data should be pulled from so that it is the results of an inner query. This function returns the modified query so that it can be chained with others
func (*Query[T]) GroupBy ¶
GroupBy sets the fields that rows should be grouped by, returning the modified query so that this function can be chained with others
func (*Query[T]) Limit ¶ added in v1.1.47
Limit sets the limit on the number of rows that may be returned by the query
func (*Query[T]) Offset ¶ added in v1.1.47
Offset sets the offset on the number of rows that should be skipped before being returned by the query
func (*Query[T]) OrderBy ¶
OrderBy sets the fields that rows should be sorted by, returning the modified query so that this function can be chained with others
func (*Query[T]) Run ¶
Run runs the query against a provided database connection, returning the query results
func (*Query[T]) Select ¶
Select determines which fields should be selected in the query, returning the modified query so that this function can be chained with others
func (*Query[T]) Where ¶
func (query *Query[T]) Where(op string, clauses ...WhereClause[T]) *Query[T]
Where sets the filter clauses that should be used to determine which rows are returned from the query. The op variable should be either AND or OR and is used to chain the clauses together. This function returns the modified query so that it can be cahined with other functions.
type WhereClause ¶
WhereClause describes the functionality that should exist in any where clause term