Documentation
¶
Overview ¶
Package qb contains the SQL QueryBuilder types and functions
Index ¶
- Constants
- Variables
- func AddType[T any](this *Instance, structRef *T) error
- func AssertNothing(_ sql.Result) bool
- func Exec(q Query, dbc db.Conn) (sql.Result, error)
- func ExecTx(q Query, tx db.Tx, checker ResultChecker) (sql.Result, error)
- func LastInsertID(result sql.Result) (uint, bool)
- func Rollback(tx db.Tx, err error) error
- func RowsAffected(result sql.Result) int
- func ToRow[T any](this *Instance, structRef *T) dict.Object
- func ToString(q Query) string
- func Update[T, V any](this *Instance, q *UpdateQuery[T], fieldRef *V, value V)
- type ColumnOrder
- type Condition
- func And(conditions ...Condition) Condition
- func Equal[T comparable](this *Instance, fieldRef *T, value T) Condition
- func Greater[T cmp.Ordered](this *Instance, fieldRef *T, value T) Condition
- func GreaterEqual[T cmp.Ordered](this *Instance, fieldRef *T, value T) Condition
- func In[T comparable](this *Instance, fieldRef *T, values ds.List[T]) Condition
- func Lesser[T cmp.Ordered](this *Instance, fieldRef *T, value T) Condition
- func LesserEqual[T cmp.Ordered](this *Instance, fieldRef *T, value T) Condition
- func NoCondition() Condition
- func NotEqual[T comparable](this *Instance, fieldRef *T, value T) Condition
- func NotIn[T comparable](this *Instance, fieldRef *T, values ds.List[T]) Condition
- func Or(conditions ...Condition) Condition
- func Prefix(this *Instance, fieldRef *string, value string) Condition
- func Substring(this *Instance, fieldRef *string, value string) Condition
- func Suffix(this *Instance, fieldRef *string, value string) Condition
- type CountQuery
- func (q *CountQuery[T]) BuildQuery() (string, []any)
- func (q *CountQuery[T]) Count(dbc db.Conn) (int, error)
- func (q *CountQuery[T]) Exists(dbc db.Conn) (bool, error)
- func (q *CountQuery) Test(item T) bool
- func (q *CountQuery) Where(condition Condition)
- func (q *CountQuery) Where2(condition DualCondition[T])
- type DeleteQuery
- func (q *DeleteQuery[T]) BuildQuery() (string, []any)
- func (q *DeleteQuery) Limit(limit uint) *orderedLimit
- func (q *DeleteQuery) OrderAsc(this *Instance, column string) *orderedLimit
- func (q *DeleteQuery) OrderDesc(this *Instance, column string) *orderedLimit
- func (q *DeleteQuery) Test(item T) bool
- func (q *DeleteQuery) Where(condition Condition)
- func (q *DeleteQuery) Where2(condition DualCondition[T])
- type DistinctValuesQuery
- func (q *DistinctValuesQuery[T, V]) BuildQuery() (string, []any)
- func (q *DistinctValuesQuery[T, V]) Query(this *Instance, dbc db.Conn) ([]V, error)
- func (q *DistinctValuesQuery) Test(item T) bool
- func (q *DistinctValuesQuery) Where(condition Condition)
- func (q *DistinctValuesQuery) Where2(condition DualCondition[T])
- type DualCondition
- func And2[T any](conditions ...DualCondition[T]) DualCondition[T]
- func Equal2[T any, V comparable](this *Instance, fieldRef *V, value V) DualCondition[T]
- func Greater2[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
- func GreaterEqual2[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
- func In2[T any, V comparable](this *Instance, fieldRef *V, values ds.List[V]) DualCondition[T]
- func Lesser2[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
- func LesserEqual2[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
- func NoCondition2[T any]() DualCondition[T]
- func NotEqual2[T any, V comparable](this *Instance, fieldRef *V, value V) DualCondition[T]
- func NotIn2[T any, V comparable](this *Instance, fieldRef *V, values ds.List[V]) DualCondition[T]
- func Or2[T any](conditions ...DualCondition[T]) DualCondition[T]
- func Prefix2[T any](this *Instance, fieldRef *string, value string) DualCondition[T]
- func Substring2[T any](this *Instance, fieldRef *string, value string) DualCondition[T]
- func Suffix2[T any](this *Instance, fieldRef *string, value string) DualCondition[T]
- type FieldUpdate
- type FieldUpdates
- type GroupCountQuery
- type GroupSumQuery
- type InsertRowQuery
- type InsertRowsQuery
- type Instance
- func (i *Instance) Column(fieldRef any) string
- func (i *Instance) Columns(fieldRefs ...any) ds.List[string]
- func (i *Instance) Field(typeName string, fieldRef any) string
- func (i *Instance) Fields(typeName string, fieldRefs ...any) ds.List[string]
- func (i *Instance) LookupColumnName(fieldRef any) (string, bool)
- type LookupQuery
- type Query
- type ResultChecker
- type RowReader
- type SelectRowQuery
- func (q *SelectRowQuery[T]) BuildQuery() (string, []any)
- func (q *SelectRowQuery) Columns(this *Instance, columns ...string)
- func (q *SelectRowQuery[T]) QueryRow(dbc db.Conn) (T, error)
- func (q *SelectRowQuery) Test(item T) bool
- func (q *SelectRowQuery) Where(condition Condition)
- func (q *SelectRowQuery) Where2(condition DualCondition[T])
- type SelectRowsQuery
- func (q *SelectRowsQuery[T]) BuildQuery() (string, []any)
- func (q *SelectRowsQuery) Columns(this *Instance, columns ...string)
- func (q *SelectRowsQuery) Limit(limit uint) *orderedLimit
- func (q *SelectRowsQuery) OrderAsc(this *Instance, column string) *orderedLimit
- func (q *SelectRowsQuery) OrderDesc(this *Instance, column string) *orderedLimit
- func (q *SelectRowsQuery[T]) Page(number, batchSize uint)
- func (q *SelectRowsQuery[T]) Query(dbc db.Conn) ([]T, error)
- func (q *SelectRowsQuery) Test(item T) bool
- func (q *SelectRowsQuery) Where(condition Condition)
- func (q *SelectRowsQuery) Where2(condition DualCondition[T])
- type SumQuery
- type TopRowQuery
- func (q *TopRowQuery[T]) BuildQuery() (string, []any)
- func (q *TopRowQuery) Columns(this *Instance, columns ...string)
- func (q *TopRowQuery) Limit(limit uint) *orderedLimit
- func (q *TopRowQuery) OrderAsc(this *Instance, column string) *orderedLimit
- func (q *TopRowQuery) OrderDesc(this *Instance, column string) *orderedLimit
- func (q *TopRowQuery[T]) QueryRow(dbc db.Conn) (T, error)
- func (q *TopRowQuery[T]) QueryRows(dbc db.Conn) ([]T, error)
- func (q *TopRowQuery) Test(item T) bool
- func (q *TopRowQuery) Where(condition Condition)
- func (q *TopRowQuery) Where2(condition DualCondition[T])
- type TopValueQuery
- func (q *TopValueQuery[T, V]) BuildQuery() (string, []any)
- func (q *TopValueQuery) Limit(limit uint) *orderedLimit
- func (q *TopValueQuery) OrderAsc(this *Instance, column string) *orderedLimit
- func (q *TopValueQuery) OrderDesc(this *Instance, column string) *orderedLimit
- func (q *TopValueQuery[T, V]) QueryValue(this *Instance, dbc db.Conn) (V, error)
- func (q *TopValueQuery[T, V]) QueryValues(this *Instance, dbc db.Conn) ([]V, error)
- func (q *TopValueQuery) Test(item T) bool
- func (q *TopValueQuery) Where(condition Condition)
- func (q *TopValueQuery) Where2(condition DualCondition[T])
- type UpdateQuery
- func (q *UpdateQuery[T]) BuildQuery() (string, []any)
- func (q *UpdateQuery) Limit(limit uint) *orderedLimit
- func (q *UpdateQuery) OrderAsc(this *Instance, column string) *orderedLimit
- func (q *UpdateQuery) OrderDesc(this *Instance, column string) *orderedLimit
- func (q *UpdateQuery) Test(item T) bool
- func (q *UpdateQuery[T]) Update(this *Instance, fieldName string, value any)
- func (q *UpdateQuery[T]) Updates(this *Instance, updates FieldUpdates)
- func (q *UpdateQuery) Where(condition Condition)
- func (q *UpdateQuery) Where2(condition DualCondition[T])
- type ValueQuery
Constants ¶
const ( Asc int = 1 Desc int = -1 )
Variables ¶
var (
MySQL = dbType{"mysql"}
)
Functions ¶
func AddType ¶
AddType registers a new struct type, and stores its column and field names into the Instance.
func AssertNothing ¶
AssertNothing does not check the SQL result, it always returns true
func ExecTx ¶
ExecTx executes a given Query as part of a database transaction, and rolls back the transaction if any error occurs
func LastInsertID ¶
LastInsertID gets the last inserted ID (uint) from SQL result, returns 0 on error
func RowsAffected ¶
RowsAffected gets the number of rows affected by the SQL result, returns 0 on error
func Update ¶
func Update[T, V any](this *Instance, q *UpdateQuery[T], fieldRef *V, value V)
Update adds a column=value update to the UpdateQuery
Types ¶
type Condition ¶
type Condition interface {
BuildCondition() (string, []any) // Return (condition string, parameter values)
}
Condition interface unifies all Condition objects: BuildCondition() method outputs the condition string and parameter values
func Equal ¶
func Equal[T comparable](this *Instance, fieldRef *T, value T) Condition
Equal creates an Equal Condition
func GreaterEqual ¶
GreaterEqual creates a GreaterThanOrEqual Condition
func In ¶
func In[T comparable](this *Instance, fieldRef *T, values ds.List[T]) Condition
In creates an In Condition
func LesserEqual ¶
LesserEqual creates a LesserThanOrEqual Condition
func NotEqual ¶
func NotEqual[T comparable](this *Instance, fieldRef *T, value T) Condition
NotEqual creates a NotEqual Condition
func NotIn ¶
func NotIn[T comparable](this *Instance, fieldRef *T, values ds.List[T]) Condition
NotIn creates a NotIn Condition
type CountQuery ¶
type CountQuery[T any] struct { // contains filtered or unexported fields }
CountQuery counts the number of rows that satisfy the condition
func NewCountQuery ¶
func NewCountQuery[T any](this *Instance, table string) *CountQuery[T]
NewCountQuery creates a new CountQuery
func (*CountQuery[T]) BuildQuery ¶
func (q *CountQuery[T]) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of CountQuery
func (*CountQuery[T]) Count ¶
func (q *CountQuery[T]) Count(dbc db.Conn) (int, error)
Count returns the number of rows that satisfy the CountQuery
func (*CountQuery[T]) Exists ¶
func (q *CountQuery[T]) Exists(dbc db.Conn) (bool, error)
Exists checks if there is at least 1 row that satisfies the CountQuery
func (*CountQuery) Test ¶
func (q *CountQuery) Test(item T) bool
Test uses the test function of the DualCondition
func (*CountQuery) Where ¶
func (q *CountQuery) Where(condition Condition)
Where sets the Query Condition
func (*CountQuery) Where2 ¶ added in v0.3.13
func (q *CountQuery) Where2(condition DualCondition[T])
type DeleteQuery ¶
type DeleteQuery[T any] struct { // contains filtered or unexported fields }
DeleteQuery is used to delete rows from the table
func NewDeleteQuery ¶
func NewDeleteQuery[T any](this *Instance, table string) *DeleteQuery[T]
NewDeleteQuery creates a new DeleteQuery
func (*DeleteQuery[T]) BuildQuery ¶
func (q *DeleteQuery[T]) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of DeleteQuery
func (*DeleteQuery) Limit ¶
func (q *DeleteQuery) Limit(limit uint) *orderedLimit
Limit sets the query limit, returns orderedLimit for chaining. Setting to 0 removes the limit
func (*DeleteQuery) OrderAsc ¶
OrderAsc adds a column with ascending order, returns orderedLimit for chaining
func (*DeleteQuery) OrderDesc ¶
OrderDesc adds a column with descending order, returns orderedLimit for chaining
func (*DeleteQuery) Test ¶
func (q *DeleteQuery) Test(item T) bool
Test uses the test function of the DualCondition
func (*DeleteQuery) Where ¶
func (q *DeleteQuery) Where(condition Condition)
Where sets the Query Condition
func (*DeleteQuery) Where2 ¶ added in v0.3.13
func (q *DeleteQuery) Where2(condition DualCondition[T])
type DistinctValuesQuery ¶
type DistinctValuesQuery[T, V any] struct { // contains filtered or unexported fields }
DistinctValuesQuery selects the distinct values for specified column that satisfies the condition T = object type, V = value type
func NewDistinctValuesQuery ¶
func NewDistinctValuesQuery[T, V any](this *Instance, table string, fieldRef *V) *DistinctValuesQuery[T, V]
NewDistinctValuesQuery creates a new DistinctValuesQuery
func (*DistinctValuesQuery[T, V]) BuildQuery ¶
func (q *DistinctValuesQuery[T, V]) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of DistinctValuesQuery
func (*DistinctValuesQuery[T, V]) Query ¶
func (q *DistinctValuesQuery[T, V]) Query(this *Instance, dbc db.Conn) ([]V, error)
Query executes the DistinctValuesQuery and returns the list of distinct values
func (*DistinctValuesQuery) Test ¶
func (q *DistinctValuesQuery) Test(item T) bool
Test uses the test function of the DualCondition
func (*DistinctValuesQuery) Where ¶
func (q *DistinctValuesQuery) Where(condition Condition)
Where sets the Query Condition
func (*DistinctValuesQuery) Where2 ¶ added in v0.3.13
func (q *DistinctValuesQuery) Where2(condition DualCondition[T])
type DualCondition ¶
DualCondition interface holds a Condition Builder and a struct Tester
func And2 ¶ added in v0.3.13
func And2[T any](conditions ...DualCondition[T]) DualCondition[T]
And2 creates an And Combo
func Equal2 ¶ added in v0.3.13
func Equal2[T any, V comparable](this *Instance, fieldRef *V, value V) DualCondition[T]
Equal2 creates an Equal Combo
func Greater2 ¶ added in v0.3.13
func Greater2[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
Greater2 creates a GreaterThan Combo
func GreaterEqual2 ¶ added in v0.3.13
func GreaterEqual2[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
GreaterEqual2 creates a GreaterThanOrEqual Combo
func In2 ¶ added in v0.3.13
func In2[T any, V comparable](this *Instance, fieldRef *V, values ds.List[V]) DualCondition[T]
In2 creates an In Combo
func Lesser2 ¶ added in v0.3.13
func Lesser2[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
Lesser2 creates a LesserThan Combo
func LesserEqual2 ¶ added in v0.3.13
func LesserEqual2[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
LesserEqual2 creates a LesserThanOrEqual Combo
func NoCondition2 ¶ added in v0.3.13
func NoCondition2[T any]() DualCondition[T]
NoCondition2 creates a matchAllCombo
func NotEqual2 ¶ added in v0.3.13
func NotEqual2[T any, V comparable](this *Instance, fieldRef *V, value V) DualCondition[T]
NotEqual2 creates a NotEqual Combo
func NotIn2 ¶ added in v0.3.13
func NotIn2[T any, V comparable](this *Instance, fieldRef *V, values ds.List[V]) DualCondition[T]
NotIn2 creates a NotIn Combo
func Or2 ¶ added in v0.3.13
func Or2[T any](conditions ...DualCondition[T]) DualCondition[T]
Or2 creates an Or Combo
func Prefix2 ¶ added in v0.3.13
func Prefix2[T any](this *Instance, fieldRef *string, value string) DualCondition[T]
Prefix2 creates a Prefix Combo
func Substring2 ¶ added in v0.3.13
func Substring2[T any](this *Instance, fieldRef *string, value string) DualCondition[T]
Substring2 creates a Substring Combo
type FieldUpdate ¶
type FieldUpdate [2]any // [OldValue, NewValue]
func (FieldUpdate) Unpack ¶
func (f FieldUpdate) Unpack() (any, any)
Unpack returns the oldValue and newValue of the FieldUpdate
type FieldUpdates ¶
type FieldUpdates map[string]FieldUpdate // {FieldName => [OldValue, NewValue]}
type GroupCountQuery ¶
type GroupCountQuery[T any, K comparable] struct { // contains filtered or unexported fields }
GroupCountQuery gets the counts of rows grouped by a column
func NewGroupCountQuery ¶
func NewGroupCountQuery[T any, K comparable](this *Instance, table string, groupFieldRef *K) *GroupCountQuery[T, K]
NewGroupCountQuery creates a new GroupCountQuery
func (*GroupCountQuery[T, K]) BuildQuery ¶
func (q *GroupCountQuery[T, K]) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of GroupCountQuery
func (*GroupCountQuery[T, K]) GroupCount ¶
func (q *GroupCountQuery[T, K]) GroupCount(dbc db.Conn) (map[K]int, error)
GroupCount executes the GroupCountQuery and returns the map[group]count
func (*GroupCountQuery) Test ¶
func (q *GroupCountQuery) Test(item T) bool
Test uses the test function of the DualCondition
func (*GroupCountQuery) Where ¶
func (q *GroupCountQuery) Where(condition Condition)
Where sets the Query Condition
func (*GroupCountQuery) Where2 ¶ added in v0.3.13
func (q *GroupCountQuery) Where2(condition DualCondition[T])
type GroupSumQuery ¶
type GroupSumQuery[T any, K comparable, V number.Type] struct { // contains filtered or unexported fields }
GroupSumQuery gets the sum of row columns grouped by a column
func NewGroupSumQuery ¶
func NewGroupSumQuery[T any, K comparable, V number.Type](this *Instance, table string, groupFieldRef *K, sumFieldRef *V) *GroupSumQuery[T, K, V]
NewGroupSumQuery creates a new GroupSumQuery
func (*GroupSumQuery[T, K, V]) BuildQuery ¶
func (q *GroupSumQuery[T, K, V]) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of GroupSumQuery
func (*GroupSumQuery[T, K, V]) GroupSum ¶
func (q *GroupSumQuery[T, K, V]) GroupSum(dbc db.Conn) (map[K]V, error)
GroupSum executes the GroupSumQuery and returns the map[group]sum
func (*GroupSumQuery) Test ¶
func (q *GroupSumQuery) Test(item T) bool
Test uses the test function of the DualCondition
func (*GroupSumQuery) Where ¶
func (q *GroupSumQuery) Where(condition Condition)
Where sets the Query Condition
func (*GroupSumQuery) Where2 ¶ added in v0.3.13
func (q *GroupSumQuery) Where2(condition DualCondition[T])
type InsertRowQuery ¶
type InsertRowQuery struct {
// contains filtered or unexported fields
}
InsertRowQuery is used to insert one row to the table
func NewInsertRowQuery ¶
func NewInsertRowQuery(this *Instance, table string) *InsertRowQuery
NewInsertRowQuery creates a new InsertRowQuery
func (*InsertRowQuery) BuildQuery ¶
func (q *InsertRowQuery) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of InsertRowQuery
type InsertRowsQuery ¶
type InsertRowsQuery struct {
// contains filtered or unexported fields
}
InsertRowsQuery is used to insert multiple rows to the table
func NewInsertRowsQuery ¶
func NewInsertRowsQuery(this *Instance, table string) *InsertRowsQuery
NewInsertRowsQuery creates a new InsertRowsQuery
func (*InsertRowsQuery) BuildQuery ¶
func (q *InsertRowsQuery) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of InsertRowsQuery
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance type stores the needed QueryBuilder data for registered types' columns and fields
func NewInstance ¶
func NewInstance(db dbType) *Instance
NewInstance creates a new QueryBuilder Instance
func (*Instance) Column ¶
Column gets the associated column name for the given struct field reference. The struct field reference must come from the Type singleton object used during registration. Returns empty string if the column name is not found.
func (*Instance) Columns ¶
Columns gets the associated column names of given struct field references. The struct field references must come from the Type singleton object used during registration. Returns empty list if at least one column name is not found.
func (*Instance) Field ¶
Field gets the associated field name for the given struct field reference. The struct field reference must come from the Type singleton object used during registration.
type LookupQuery ¶
type LookupQuery[T any, K comparable, V any] struct { // contains filtered or unexported fields }
LookupQuery selects two columns from a table and creates a lookup map for rows that satisfy the condition T = object type, K = key type, V = value type
func NewLookupQuery ¶
func NewLookupQuery[T any, K comparable, V any](this *Instance, table string, keyFieldRef *K, valueFieldRef *V) *LookupQuery[T, K, V]
NewLookupQuery creates a new LookupQuery
func (*LookupQuery[T, K, V]) BuildQuery ¶
func (q *LookupQuery[T, K, V]) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of LookupQuery
func (*LookupQuery[T, K, V]) Lookup ¶
func (q *LookupQuery[T, K, V]) Lookup(this *Instance, dbc db.Conn) (map[K]V, error)
Lookup executes the LookupQuery and returns the map[K]V lookup
func (*LookupQuery) Test ¶
func (q *LookupQuery) Test(item T) bool
Test uses the test function of the DualCondition
func (*LookupQuery) Where ¶
func (q *LookupQuery) Where(condition Condition)
Where sets the Query Condition
func (*LookupQuery) Where2 ¶ added in v0.3.13
func (q *LookupQuery) Where2(condition DualCondition[T])
type Query ¶
Query interface unifies all Query types: BuildQuery() method outputs the query string and parameter values
type ResultChecker ¶
ResultChecker is a function that checks the SQL result if a condition is satisfied
func AssertRowsAffected ¶
func AssertRowsAffected(expected int) ResultChecker
AssertRowsAffected checks if the SQL result has the expected number of affected rows
type RowReader ¶
type RowReader[T any] = func(db.RowScanner) (T, error)
RowReader is a function that reads row values into a struct
func FullRowReader ¶
FullRowReader creates a RowReader for type T, using all columns
type SelectRowQuery ¶
type SelectRowQuery[T any] struct { // contains filtered or unexported fields }
SelectRowQuery selects a single row from the table that satisfies the condition
func NewFullSelectRowQuery ¶
func NewFullSelectRowQuery[T any](this *Instance, table string, reader RowReader[T]) *SelectRowQuery[T]
NewFullSelectRowQuery creates a new SelectRowQuery, which uses all columns
func NewSelectRowQuery ¶
func NewSelectRowQuery[T any](this *Instance, table string, reader RowReader[T]) *SelectRowQuery[T]
NewSelectRowQuery creates a new SelectRowQuery, which only uses selected columns
func (*SelectRowQuery[T]) BuildQuery ¶
func (q *SelectRowQuery[T]) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of SelectRowQuery
func (*SelectRowQuery[T]) QueryRow ¶
func (q *SelectRowQuery[T]) QueryRow(dbc db.Conn) (T, error)
QueryRow executes the SelectRowQuery and gets the row object
func (*SelectRowQuery) Test ¶
func (q *SelectRowQuery) Test(item T) bool
Test uses the test function of the DualCondition
func (*SelectRowQuery) Where ¶
func (q *SelectRowQuery) Where(condition Condition)
Where sets the Query Condition
func (*SelectRowQuery) Where2 ¶ added in v0.3.13
func (q *SelectRowQuery) Where2(condition DualCondition[T])
type SelectRowsQuery ¶
type SelectRowsQuery[T any] struct { // contains filtered or unexported fields }
SelectRowsQuery selects the rows from the table that satisfy the condition
func NewFullSelectRowsQuery ¶
func NewFullSelectRowsQuery[T any](this *Instance, table string, reader RowReader[T]) *SelectRowsQuery[T]
NewFullSelectRowsQuery creates a new SelectRowsQuery, which uses all columns
func NewSelectRowsQuery ¶
func NewSelectRowsQuery[T any](this *Instance, table string, reader RowReader[T]) *SelectRowsQuery[T]
NewSelectRowsQuery creates a new SelectRowsQuery, which uses only selected columns
func (*SelectRowsQuery[T]) BuildQuery ¶
func (q *SelectRowsQuery[T]) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of SelectRowsQuery
func (*SelectRowsQuery) Limit ¶
func (q *SelectRowsQuery) Limit(limit uint) *orderedLimit
Limit sets the query limit, returns orderedLimit for chaining. Setting to 0 removes the limit
func (*SelectRowsQuery) OrderAsc ¶
OrderAsc adds a column with ascending order, returns orderedLimit for chaining
func (*SelectRowsQuery) OrderDesc ¶
OrderDesc adds a column with descending order, returns orderedLimit for chaining
func (*SelectRowsQuery[T]) Page ¶
func (q *SelectRowsQuery[T]) Page(number, batchSize uint)
Page sets the page number and batch size for a paginated SelectRowsQuery
func (*SelectRowsQuery[T]) Query ¶
func (q *SelectRowsQuery[T]) Query(dbc db.Conn) ([]T, error)
Query executes the SelectRowsQuery and returns the list of rows
func (*SelectRowsQuery) Test ¶
func (q *SelectRowsQuery) Test(item T) bool
Test uses the test function of the DualCondition
func (*SelectRowsQuery) Where ¶
func (q *SelectRowsQuery) Where(condition Condition)
Where sets the Query Condition
func (*SelectRowsQuery) Where2 ¶ added in v0.3.13
func (q *SelectRowsQuery) Where2(condition DualCondition[T])
type SumQuery ¶
type SumQuery[T any] struct { // contains filtered or unexported fields }
SumQuery sums up the selected columns for rows that satisfy the condition
func NewSumQuery ¶
NewSumQuery creates a new SumQuery
func (*SumQuery[T]) BuildQuery ¶
BuildQuery returns the query string and parameter values of SumQuery
func (*SumQuery) Test ¶
func (q *SumQuery) Test(item T) bool
Test uses the test function of the DualCondition
func (*SumQuery) Where ¶
func (q *SumQuery) Where(condition Condition)
Where sets the Query Condition
func (*SumQuery) Where2 ¶ added in v0.3.13
func (q *SumQuery) Where2(condition DualCondition[T])
type TopRowQuery ¶
type TopRowQuery[T any] struct { // contains filtered or unexported fields }
TopRowQuery selects the top N rows from the table that satisfy the condition
func NewTopRowQuery ¶
func NewTopRowQuery[T any](this *Instance, table string, reader RowReader[T]) *TopRowQuery[T]
NewTopRowQuery creates a new TopRowQuery
func (*TopRowQuery[T]) BuildQuery ¶
func (q *TopRowQuery[T]) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of TopRowQuery
func (*TopRowQuery) Limit ¶
func (q *TopRowQuery) Limit(limit uint) *orderedLimit
Limit sets the query limit, returns orderedLimit for chaining. Setting to 0 removes the limit
func (*TopRowQuery) OrderAsc ¶
OrderAsc adds a column with ascending order, returns orderedLimit for chaining
func (*TopRowQuery) OrderDesc ¶
OrderDesc adds a column with descending order, returns orderedLimit for chaining
func (*TopRowQuery[T]) QueryRow ¶
func (q *TopRowQuery[T]) QueryRow(dbc db.Conn) (T, error)
QueryRow executes the TopRowQuery and gets the top row object
func (*TopRowQuery[T]) QueryRows ¶
func (q *TopRowQuery[T]) QueryRows(dbc db.Conn) ([]T, error)
QueryRows executes the TopRowQuery and returns the top N row objects
func (*TopRowQuery) Test ¶
func (q *TopRowQuery) Test(item T) bool
Test uses the test function of the DualCondition
func (*TopRowQuery) Where ¶
func (q *TopRowQuery) Where(condition Condition)
Where sets the Query Condition
func (*TopRowQuery) Where2 ¶ added in v0.3.13
func (q *TopRowQuery) Where2(condition DualCondition[T])
type TopValueQuery ¶
type TopValueQuery[T, V any] struct { // contains filtered or unexported fields }
TopValueQuery selects the top N values from the table that satisfy the condition
func NewTopValueQuery ¶
func NewTopValueQuery[T, V any](this *Instance, table string, fieldRef *V) *TopValueQuery[T, V]
NewTopValueQuery creates a new TopValueQuery
func (*TopValueQuery[T, V]) BuildQuery ¶
func (q *TopValueQuery[T, V]) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of TopValueQuery
func (*TopValueQuery) Limit ¶
func (q *TopValueQuery) Limit(limit uint) *orderedLimit
Limit sets the query limit, returns orderedLimit for chaining. Setting to 0 removes the limit
func (*TopValueQuery) OrderAsc ¶
OrderAsc adds a column with ascending order, returns orderedLimit for chaining
func (*TopValueQuery) OrderDesc ¶
OrderDesc adds a column with descending order, returns orderedLimit for chaining
func (*TopValueQuery[T, V]) QueryValue ¶
func (q *TopValueQuery[T, V]) QueryValue(this *Instance, dbc db.Conn) (V, error)
QueryValue executes the TopValueQuery and gets the top column value
func (*TopValueQuery[T, V]) QueryValues ¶
func (q *TopValueQuery[T, V]) QueryValues(this *Instance, dbc db.Conn) ([]V, error)
QueryValues executes the TopValueQuery and gets the top N column values
func (*TopValueQuery) Test ¶
func (q *TopValueQuery) Test(item T) bool
Test uses the test function of the DualCondition
func (*TopValueQuery) Where ¶
func (q *TopValueQuery) Where(condition Condition)
Where sets the Query Condition
func (*TopValueQuery) Where2 ¶ added in v0.3.13
func (q *TopValueQuery) Where2(condition DualCondition[T])
type UpdateQuery ¶
type UpdateQuery[T any] struct { // contains filtered or unexported fields }
UpdateQuery is used to update rows in the table
func NewUpdateQuery ¶
func NewUpdateQuery[T any](this *Instance, table string) *UpdateQuery[T]
NewUpdateQuery creates a new UpdateQuery
func (*UpdateQuery[T]) BuildQuery ¶
func (q *UpdateQuery[T]) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of UpdateQuery
func (*UpdateQuery) Limit ¶
func (q *UpdateQuery) Limit(limit uint) *orderedLimit
Limit sets the query limit, returns orderedLimit for chaining. Setting to 0 removes the limit
func (*UpdateQuery) OrderAsc ¶
OrderAsc adds a column with ascending order, returns orderedLimit for chaining
func (*UpdateQuery) OrderDesc ¶
OrderDesc adds a column with descending order, returns orderedLimit for chaining
func (*UpdateQuery) Test ¶
func (q *UpdateQuery) Test(item T) bool
Test uses the test function of the DualCondition
func (*UpdateQuery[T]) Update ¶
func (q *UpdateQuery[T]) Update(this *Instance, fieldName string, value any)
Update adds a column=value update to the UpdateQuery. Note: We lose type-checking of value here, so must be sure that field=value are of the same type.
func (*UpdateQuery[T]) Updates ¶
func (q *UpdateQuery[T]) Updates(this *Instance, updates FieldUpdates)
Updates adds column=value updates to the UpdateQuery Note: We lose type-checking of value here, so must be sure that field=value are of the same type.
func (*UpdateQuery) Where ¶
func (q *UpdateQuery) Where(condition Condition)
Where sets the Query Condition
func (*UpdateQuery) Where2 ¶ added in v0.3.13
func (q *UpdateQuery) Where2(condition DualCondition[T])
type ValueQuery ¶
type ValueQuery[T, V any] struct { // contains filtered or unexported fields }
ValueQuery selects a single column value from the table from one row that satisfies the condition Type T = object type, V = value type
func NewValueQuery ¶
func NewValueQuery[T, V any](this *Instance, table string, fieldRef *V) *ValueQuery[T, V]
NewValueQuery creates a new ValueQuery
func (*ValueQuery[T, V]) BuildQuery ¶
func (q *ValueQuery[T, V]) BuildQuery() (string, []any)
BuildQuery returns the query string and parameter values of ValueQuery
func (*ValueQuery[T, V]) QueryValue ¶
func (q *ValueQuery[T, V]) QueryValue(this *Instance, dbc db.Conn) (V, error)
QueryValue executes the ValueQuery and gets the column value
func (*ValueQuery) Test ¶
func (q *ValueQuery) Test(item T) bool
Test uses the test function of the DualCondition
func (*ValueQuery) Where ¶
func (q *ValueQuery) Where(condition Condition)
Where sets the Query Condition
func (*ValueQuery) Where2 ¶ added in v0.3.13
func (q *ValueQuery) Where2(condition DualCondition[T])