qb

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 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) ds.Result[sql.Result]

Exec executes the given Query, and returns the SQL Result

func ExecTx

func ExecTx(q Query, tx db.Tx, checker ResultChecker) ds.Result[sql.Result]

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 AndCondition

func AndCondition(conditions ...Condition) Condition

AndCondition creates an And Condition

func EmptyCondition

func EmptyCondition() Condition

EmptyCondition creates a matchAllCondition

func EqualTo

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

EqualTo creates an Equal Condition

func GreaterEqualTo

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

GreaterEqualTo creates a GreaterThanOrEqual Condition

func GreaterThan

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

GreaterThan creates a GreaterThan Condition

func HasPrefix

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

HasPrefix creates a Prefix Condition

func HasSubstring

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

HasSubstring creates a Substring Condition

func HasSuffix

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

HasSuffix creates a Suffix Condition

func InValues

func InValues[T comparable](this *Instance, fieldRef *T, values ds.List[T]) Condition

InValues creates an In Condition

func LesserEqualTo

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

LesserEqualTo creates a LesserThanOrEqual Condition

func LesserThan

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

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

func OrCondition(conditions ...Condition) Condition

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

func (q *CountQuery[T]) Count(dbc db.Conn) ds.Result[int]

Count returns the number of rows that satisfy the CountQuery

func (*CountQuery[T]) Exists

func (q *CountQuery[T]) Exists(dbc db.Conn) ds.Result[bool]

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

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

func (q *DistinctValuesQuery[T, V]) Query(this *Instance, dbc db.Conn) ds.Result[[]V]

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

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

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 NoCondition

func NoCondition[T any]() DualCondition[T]

NoCondition creates a matchAllCombo

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 Or

func Or[T any](conditions ...DualCondition[T]) DualCondition[T]

Or creates an Or Combo

func Prefix

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

Prefix creates a Prefix Combo

func Substring

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

Substring creates a Substring Combo

func Suffix

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

Suffix 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) ds.Result[map[K]int]

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

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) ds.Result[map[K]V]

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

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) ds.Result[T]

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

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) ds.Result[T]

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

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) ds.Result[V]

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) ds.Result[[]V]

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

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

func (q *ValueQuery[T, V]) QueryValue(this *Instance, dbc db.Conn) ds.Result[V]

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

Jump to

Keyboard shortcuts

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