Documentation
¶
Overview ¶
Package qb contains the SQL QueryBuilder types and functions
Index ¶
- Variables
- func AddType[T any](this *Instance, structRef *T) error
- func AssertNothing(_ sql.Result) bool
- func Exec(q Query, dbc db.Conn) ds.Result[sql.Result]
- func ExecTx(q Query, tx db.Tx, checker ResultChecker) ds.Result[sql.Result]
- 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 Condition
- func AndCondition(conditions ...Condition) Condition
- func EmptyCondition() Condition
- func EqualTo[T comparable](this *Instance, fieldRef *T, value T) Condition
- func GreaterEqualTo[T cmp.Ordered](this *Instance, fieldRef *T, value T) Condition
- func GreaterThan[T cmp.Ordered](this *Instance, fieldRef *T, value T) Condition
- func HasPrefix(this *Instance, fieldRef *string, value string) Condition
- func HasSubstring(this *Instance, fieldRef *string, value string) Condition
- func HasSuffix(this *Instance, fieldRef *string, value string) Condition
- func InValues[T comparable](this *Instance, fieldRef *T, values ds.List[T]) Condition
- func LesserEqualTo[T cmp.Ordered](this *Instance, fieldRef *T, value T) Condition
- func LesserThan[T cmp.Ordered](this *Instance, fieldRef *T, value T) Condition
- func NotEqualTo[T comparable](this *Instance, fieldRef *T, value T) Condition
- func NotInValues[T comparable](this *Instance, fieldRef *T, values ds.List[T]) Condition
- func OrCondition(conditions ...Condition) Condition
- type CountQuery
- 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 DualCondition[T])
- type DistinctValuesQuery
- type DualCondition
- func And[T any](conditions ...DualCondition[T]) DualCondition[T]
- func Equal[T any, V comparable](this *Instance, fieldRef *V, value V) DualCondition[T]
- func Greater[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
- func GreaterEqual[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
- func In[T any, V comparable](this *Instance, fieldRef *V, values ds.List[V]) DualCondition[T]
- func Lesser[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
- func LesserEqual[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
- func NoCondition[T any]() DualCondition[T]
- func NotEqual[T any, V comparable](this *Instance, fieldRef *V, value V) DualCondition[T]
- func NotIn[T any, V comparable](this *Instance, fieldRef *V, values ds.List[V]) DualCondition[T]
- func Or[T any](conditions ...DualCondition[T]) DualCondition[T]
- func Prefix[T any](this *Instance, fieldRef *string, value string) DualCondition[T]
- func Substring[T any](this *Instance, fieldRef *string, value string) DualCondition[T]
- func Suffix[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
- 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) ds.Result[[]T]
- func (q *SelectRowsQuery) Test(item T) bool
- func (q *SelectRowsQuery) Where(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) ds.Result[T]
- func (q *TopRowQuery[T]) QueryRows(dbc db.Conn) ds.Result[[]T]
- func (q *TopRowQuery) Test(item T) bool
- func (q *TopRowQuery) Where(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) ds.Result[V]
- func (q *TopValueQuery[T, V]) QueryValues(this *Instance, dbc db.Conn) ds.Result[[]V]
- func (q *TopValueQuery) Test(item T) bool
- func (q *TopValueQuery) Where(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 DualCondition[T])
- type ValueQuery
Constants ¶
This section is empty.
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 AndCondition ¶
AndCondition creates an And Condition
func EqualTo ¶
func EqualTo[T comparable](this *Instance, fieldRef *T, value T) Condition
EqualTo creates an Equal Condition
func GreaterEqualTo ¶
GreaterEqualTo creates a GreaterThanOrEqual Condition
func GreaterThan ¶
GreaterThan creates a GreaterThan Condition
func HasSubstring ¶
HasSubstring creates a Substring Condition
func InValues ¶
func InValues[T comparable](this *Instance, fieldRef *T, values ds.List[T]) Condition
InValues creates an In Condition
func LesserEqualTo ¶
LesserEqualTo creates a LesserThanOrEqual Condition
func LesserThan ¶
LesserThan creates a LesserThan Condition
func NotEqualTo ¶
func NotEqualTo[T comparable](this *Instance, fieldRef *T, value T) Condition
NotEqualTo creates a NotEqual Condition
func NotInValues ¶
func NotInValues[T comparable](this *Instance, fieldRef *T, values ds.List[T]) Condition
NotInValues creates a NotIn Condition
func OrCondition ¶
OrCondition creates an Or 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]) Exists ¶
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 DualCondition[T])
Where sets the Query Condition
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 DualCondition[T])
Where sets the Query Condition
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 ¶
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 DualCondition[T])
Where sets the Query Condition
type DualCondition ¶
DualCondition interface holds a Condition Builder and a struct Tester
func And ¶
func And[T any](conditions ...DualCondition[T]) DualCondition[T]
And creates an And Combo
func Equal ¶
func Equal[T any, V comparable](this *Instance, fieldRef *V, value V) DualCondition[T]
Equal creates an Equal Combo
func Greater ¶
func Greater[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
Greater creates a GreaterThan Combo
func GreaterEqual ¶
func GreaterEqual[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
GreaterEqual creates a GreaterThanOrEqual Combo
func In ¶
func In[T any, V comparable](this *Instance, fieldRef *V, values ds.List[V]) DualCondition[T]
In creates an In Combo
func Lesser ¶
func Lesser[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
Lesser creates a LesserThan Combo
func LesserEqual ¶
func LesserEqual[T any, V cmp.Ordered](this *Instance, fieldRef *V, value V) DualCondition[T]
LesserEqual creates a LesserThanOrEqual Combo
func NotEqual ¶
func NotEqual[T any, V comparable](this *Instance, fieldRef *V, value V) DualCondition[T]
NotEqual creates a NotEqual Combo
func NotIn ¶
func NotIn[T any, V comparable](this *Instance, fieldRef *V, values ds.List[V]) DualCondition[T]
NotIn creates a NotIn Combo
func Prefix ¶
func Prefix[T any](this *Instance, fieldRef *string, value string) DualCondition[T]
Prefix creates a Prefix 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 ¶
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 DualCondition[T])
Where sets the Query Condition
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) ds.Result[map[K]V]
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 DualCondition[T])
Where sets the Query Condition
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 ¶
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 DualCondition[T])
Where sets the Query Condition
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) ds.Result[T]
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) ds.Result[T]
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 DualCondition[T])
Where sets the Query Condition
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) ds.Result[[]T]
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 DualCondition[T])
Where sets the Query Condition
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 DualCondition[T])
Where sets the Query Condition
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) ds.Result[T]
QueryRow executes the TopRowQuery and gets the top row object
func (*TopRowQuery[T]) QueryRows ¶
func (q *TopRowQuery[T]) QueryRows(dbc db.Conn) ds.Result[[]T]
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 DualCondition[T])
Where sets the Query Condition
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 ¶
QueryValue executes the TopValueQuery and gets the top column value
func (*TopValueQuery[T, V]) QueryValues ¶
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 DualCondition[T])
Where sets the Query Condition
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 DualCondition[T])
Where sets the Query Condition
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 ¶
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 DualCondition[T])
Where sets the Query Condition