qb

package
v0.3.27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package qb contains the SQL QueryBuilder types and functions

Index

Constants

This section is empty.

Variables

View Source
var (
	MySQL = dbType{"mysql"}
)

Functions

func AddType

func AddType[T any](this *Instance, structRef *T) error

AddType registers a new struct type, and stores its column and field names into the Instance.

func AssertNothing

func AssertNothing(_ sql.Result) bool

AssertNothing does not check the SQL result, it always returns true

func Exec

func Exec(q Query, dbc db.Conn) (sql.Result, error)

Exec executes the given Query, and returns the SQL Result

func ExecTx

func ExecTx(q Query, tx db.Tx, checker ResultChecker) (sql.Result, error)

ExecTx executes a given Query as part of a database transaction, and rolls back the transaction if any error occurs

func LastInsertID

func LastInsertID(result sql.Result) (uint, bool)

LastInsertID gets the last inserted ID (uint) from SQL result, returns 0 on error

func Rollback

func Rollback(tx db.Tx, err error) error

Rollback rolls back the given database transaction

func RowsAffected

func RowsAffected(result sql.Result) int

RowsAffected gets the number of rows affected by the SQL result, returns 0 on error

func ToRow

func ToRow[T any](this *Instance, structRef *T) dict.Object

ToRow converts a given struct to map[string]any for row insertion

func ToString

func ToString(q Query) string

ToString builds the Query string

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 And

func And(conditions ...Condition) Condition

And creates an And Condition

func Equal

func Equal[T comparable](this *Instance, fieldRef *T, value T) Condition

Equal creates an Equal Condition

func Greater

func Greater[T cmp.Ordered](this *Instance, fieldRef *T, value T) Condition

Greater creates a GreaterThan Condition

func GreaterEqual

func GreaterEqual[T cmp.Ordered](this *Instance, fieldRef *T, value T) Condition

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 Lesser

func Lesser[T cmp.Ordered](this *Instance, fieldRef *T, value T) Condition

Lesser creates a LesserThan Condition

func LesserEqual

func LesserEqual[T cmp.Ordered](this *Instance, fieldRef *T, value T) Condition

LesserEqual creates a LesserThanOrEqual Condition

func NoCondition

func NoCondition() Condition

NoCondition creates a matchAllCondition

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

func Or

func Or(conditions ...Condition) Condition

Or creates an Or Condition

func Prefix

func Prefix(this *Instance, fieldRef *string, value string) Condition

Prefix creates a Prefix Condition

func Substring

func Substring(this *Instance, fieldRef *string, value string) Condition

Substring creates a Substring Condition

func Suffix

func Suffix(this *Instance, fieldRef *string, value string) Condition

Suffix creates a Suffix 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

func (q *DeleteQuery) OrderAsc(this *Instance, column string) *orderedLimit

OrderAsc adds a column with ascending order, returns orderedLimit for chaining

func (*DeleteQuery) OrderDesc

func (q *DeleteQuery) OrderDesc(this *Instance, column string) *orderedLimit

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

type DualCondition[T any] interface {
	Condition
	Test(T) bool
}

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

func Suffix2 added in v0.3.13

func Suffix2[T any](this *Instance, fieldRef *string, value string) DualCondition[T]

Suffix2 creates a Suffix 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

func (*InsertRowQuery) Row

func (q *InsertRowQuery) Row(this *Instance, row dict.Object)

Row sets the InsertRowQuery's row

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

func (*InsertRowsQuery) Rows

func (q *InsertRowsQuery) Rows(this *Instance, rows ...dict.Object)

Rows sets the InsertRowsQuery's rows

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

func (i *Instance) Column(fieldRef any) string

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

func (i *Instance) Columns(fieldRefs ...any) ds.List[string]

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

func (i *Instance) Field(typeName string, fieldRef any) string

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.

func (*Instance) Fields

func (i *Instance) Fields(typeName string, fieldRefs ...any) ds.List[string]

Fields gets the associated field names for the 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 field name is not found.

func (*Instance) LookupColumnName

func (i *Instance) LookupColumnName(fieldRef any) (string, bool)

LookupColumnName looks up the associated column 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

type Query interface {
	BuildQuery() (string, []any) // Return (query string, parameter values)
}

Query interface unifies all Query types: BuildQuery() method outputs the query string and parameter values

type ResultChecker

type ResultChecker = func(sql.Result) bool

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

func FullRowReader[T any](this *Instance, structRef *T) RowReader[T]

FullRowReader creates a RowReader for type T, using all columns

func NewRowReader

func NewRowReader[T any](this *Instance, columns ...string) RowReader[T]

NewRowReader creates a RowReader for type T, with the given 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) Columns

func (q *SelectRowQuery) Columns(this *Instance, columns ...string)

Columns sets the columns of columnsReader

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) Columns

func (q *SelectRowsQuery) Columns(this *Instance, columns ...string)

Columns sets the columns of columnsReader

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

func (q *SelectRowsQuery) OrderAsc(this *Instance, column string) *orderedLimit

OrderAsc adds a column with ascending order, returns orderedLimit for chaining

func (*SelectRowsQuery) OrderDesc

func (q *SelectRowsQuery) OrderDesc(this *Instance, column string) *orderedLimit

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

func NewSumQuery[T any](this *Instance, table string, reader RowReader[T]) *SumQuery[T]

NewSumQuery creates a new SumQuery

func (*SumQuery[T]) BuildQuery

func (q *SumQuery[T]) BuildQuery() (string, []any)

BuildQuery returns the query string and parameter values of SumQuery

func (*SumQuery) Columns

func (q *SumQuery) Columns(this *Instance, columns ...string)

Columns sets the columns of columnsReader

func (*SumQuery[T]) Sum

func (q *SumQuery[T]) Sum(dbc db.Conn) (T, error)

Sum executes the SumQuery and returns an object with the sum values

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) Columns

func (q *TopRowQuery) Columns(this *Instance, columns ...string)

Columns sets the columns of columnsReader

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

func (q *TopRowQuery) OrderAsc(this *Instance, column string) *orderedLimit

OrderAsc adds a column with ascending order, returns orderedLimit for chaining

func (*TopRowQuery) OrderDesc

func (q *TopRowQuery) OrderDesc(this *Instance, column string) *orderedLimit

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

func (q *TopValueQuery) OrderAsc(this *Instance, column string) *orderedLimit

OrderAsc adds a column with ascending order, returns orderedLimit for chaining

func (*TopValueQuery) OrderDesc

func (q *TopValueQuery) OrderDesc(this *Instance, column string) *orderedLimit

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

func (q *UpdateQuery) OrderAsc(this *Instance, column string) *orderedLimit

OrderAsc adds a column with ascending order, returns orderedLimit for chaining

func (*UpdateQuery) OrderDesc

func (q *UpdateQuery) OrderDesc(this *Instance, column string) *orderedLimit

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])

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL