common

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: Apache-2.0 Imports: 5 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// ZeroLimit is used to signal to AddLimit to include a `LIMIT 0` clause
	ZeroLimit = -1
)

Variables

This section is empty.

Functions

func NewAliasedTable

func NewAliasedTable(name TableName, alias TableAlias) aliasedTable

func NewBuilder

func NewBuilder() *builder

func NewBuilderWithOffset

func NewBuilderWithOffset(pc *int) *builder

func NewTable

func NewTable(name TableName) aliasedTable

TODO: Support new alias per table in case a table is selected twice in the same query (for different joins)

Types

type Builder

type Builder interface {
	WriteParam(Param) Builder
	WriteTuples([]Tuple) Builder
	WriteString(string) Builder
	WriteRune(rune) Builder
	WriteSerializables(...Serializable) Builder
	WriteConditionSerializable(ConditionSerializable, CondInterpreter) Builder
	Build() (string, []Param)
}

Builder is the string builder

type CondInterpreter

type CondInterpreter interface {
	// TimeOffset appends NOW() - '10 seconds'
	TimeOffset(duration time.Duration, sb Builder)
	// InTuple creates the condition (field1, field2, ...) IN ((val1, val2, ...), (val3, val4, ...))
	InTuple(fields []Serializable, vals []Tuple, sb Builder)
}

CondInterpreter is the condition interpreter for the WHERE clauses It specifies the behaviors that differ among different DBs

type Condition added in v0.6.0

type Condition ConditionSerializable

type ConditionSerializable

type ConditionSerializable interface {
	WriteString(CondInterpreter, Builder)
}

ConditionSerializable is any type that can be transformed to a query part but needs condition interpreter support, e.g. condition, join

type Field

type Field Serializable

type FieldName

type FieldName string

FieldName is the name of the DB column

func (FieldName) WriteString

func (n FieldName) WriteString(b Builder)

type JoinType added in v0.6.0

type JoinType int
const (
	Left JoinType = iota
	Right
	Full
	Inner
	Cross
)

type JoinedTable

type JoinedTable interface {
	ConditionSerializable
	JoinAs(typ JoinType, other Table, ons ConditionSerializable) JoinedTable
	Join(Table, ConditionSerializable) JoinedTable
}

type ModifiableQuery added in v0.6.0

type ModifiableQuery interface {
	AddField(Field)
	AddWhere(Condition)
	AddOrderBy(OrderBy)
	// AddLimit is used to manage the LIMIT clause.
	// Any passed value larger than zero will trigger the inclusion of the clause.
	// If one wants to explicitly insert a clause as `LIMIT 0`, then oen should use the constant ZeroLimit
	AddLimit(int)
	AddOffset(int)
}

type OrderBy added in v0.6.0

type OrderBy Serializable

type PagInterpreter

type PagInterpreter interface {
	// PreProcess modifies the SQL query to add pagination support
	PreProcess(driver.Pagination, ModifiableQuery)
}

PagInterpreter is the pagination interpreter

type Param

type Param = any

Param is a value for a field

type Serializable

type Serializable interface {
	WriteString(Builder)
}

Serializable is any type can be transformed to a query part, e.g. field, order-by

func ToSerializables

func ToSerializables[S Serializable](vs []S) []Serializable

type Table

type Table interface {
	JoinedTable
	Field(name FieldName) Field
}

type TableAlias

type TableAlias string

type TableName

type TableName string

type Tuple

type Tuple = []Param

Tuple is a tuple of parameters

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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