qb

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SQLNow is the SQL NOW() function for use as a value in expressions.
	SQLNow = "NOW()"

	// SQLNull is the SQL representation of NULL
	SQLNull = "NULL"
)
View Source
const (
	// Equal Comparison Operator
	Equal Comparison = "="
	// NotEqual Comparison Operator
	NotEqual Comparison = "!="
	// LessThan Comparison Operator
	LessThan Comparison = "<"
	// LessThanEqual Comparison Operator
	LessThanEqual Comparison = "<="
	// GreaterThan Comparison Operator
	GreaterThan Comparison = ">"
	// GreaterThanEqual Comparison Operator
	GreaterThanEqual Comparison = ">="
	// NullSafeEqual Comparison Operator
	NullSafeEqual Comparison = "<=>"
	// Is Comparison Operator
	Is Comparison = "IS"
	// IsNot Comparison Operator
	IsNot Comparison = "IS NOT"
	// In Comparison Operator
	In Comparison = "IN"
	// LIKE Comparison Operator
	Like Comparison = "LIKE"
	// Inner JoinType
	Inner JoinType = "INNER"
	// Outer JoinType
	Outer JoinType = "OUTER"
	// Cross JoinType
	Cross JoinType = "CROSS"
	// Left JoinDirection
	Left JoinDirection = "LEFT"
	// Right JoinDirection
	Right JoinDirection = "RIGHT"
	// Ascending OrderDirection
	Ascending OrderDirection = "ASC"
	// Descending OrderDirection
	Descending OrderDirection = "DESC"
	// And expression conjunction
	And = "AND"
	// Or expression conjunction
	Or = "OR"
	// XOr expression conjunction
	XOr = "XOR"
	// NoLimit is the value that represents not applying a limit on the query
	NoLimit = 0
)

Variables

This section is empty.

Functions

func NewMissingTablesError

func NewMissingTablesError(tables []string) errors.TracerError

NewMissingTablesError is returned when column's are being used from a table that is not part of the query.

func NewValidationFromNotSetError

func NewValidationFromNotSetError() errors.TracerError

NewValidationFromNotSetError instantiates a ValidationFromNotSetError with a stack trace

Types

type Comparison

type Comparison string

Comparison of two fields

type ConditionExpression

type ConditionExpression struct {
	// contains filtered or unexported fields
}

ConditionExpression represents an expression that can be used as a condition in a where or join on.

func FieldComparison

func FieldComparison(left TableField, comparison Comparison, right interface{}) *ConditionExpression

FieldComparison to another field or a discrete value.

func FieldIn

func FieldIn(left TableField, in ...interface{}) *ConditionExpression

FieldIn a series of TableFields and/or values

func (*ConditionExpression) And

And creates an expression with this and the passed expression with an AND conjunction.

func (*ConditionExpression) Or

Or creates an expression with this and the passed expression with an OR conjunction.

func (*ConditionExpression) SQL

func (exp *ConditionExpression) SQL() (string, []interface{})

SQL returns this condition expression as a SQL expression.

func (*ConditionExpression) Tables

func (exp *ConditionExpression) Tables() []string

Tables that are used in this expression or it's sub expressions.

func (*ConditionExpression) XOr

XOr creates an expression with this and the passed expression with an XOr conjunction.

type DeleteQuery

type DeleteQuery struct {
	// contains filtered or unexported fields
}

DeleteQuery for removing rows from a database

func Delete

func Delete(rowsIn ...Table) *DeleteQuery

Delete from from the specified tables that match the criteria specified in where.

func (*DeleteQuery) From

func (q *DeleteQuery) From(table Table) *DeleteQuery

From sets the primary table the query will find rows in.

func (*DeleteQuery) GetAlias

func (q *DeleteQuery) GetAlias(tableName string) string

GetAlias of the passed table name in this query

func (*DeleteQuery) InnerJoin

func (q *DeleteQuery) InnerJoin(table Table) *Join

InnerJoin with another table in the database.

func (*DeleteQuery) OuterJoin

func (q *DeleteQuery) OuterJoin(direction JoinDirection, table Table) *Join

OuterJoin with another table in the database.

func (*DeleteQuery) SQL

func (q *DeleteQuery) SQL() (string, []interface{}, error)

SQL representation of this delete query.

func (*DeleteQuery) Validate

func (q *DeleteQuery) Validate() bool

Validate that this query is executable

func (*DeleteQuery) Where

func (q *DeleteQuery) Where(condition *ConditionExpression) *DeleteQuery

Where determines what rows to delete from.

type InsertQuery

type InsertQuery struct {
	// contains filtered or unexported fields
}

InsertQuery for inserting a row into the database.

func Insert

func Insert(columns ...TableField) *InsertQuery

Insert columns into a table

func (*InsertQuery) GetAlias

func (q *InsertQuery) GetAlias(tableName string) string

GetAlias of the passed table name in this query.

func (*InsertQuery) OnDuplicate

func (q *InsertQuery) OnDuplicate(fields []TableField, values ...interface{}) *InsertQuery

OnDuplicate update these fields / values

func (*InsertQuery) ParameterizedSQL

func (q *InsertQuery) ParameterizedSQL() (string, error)

ParameterizedSQL that represents this insert query.

func (*InsertQuery) SQL

func (q *InsertQuery) SQL() (string, []interface{}, error)

SQL that represents this insert query.

func (*InsertQuery) Values

func (q *InsertQuery) Values(values ...interface{}) *InsertQuery

Values to be inserted. Call multiple times to insert multiple rows.

type Join

type Join struct {
	// contains filtered or unexported fields
}

Join on the tables inside the query.

func NewJoin

func NewJoin(joinType JoinType, joinDirection JoinDirection, table Table) *Join

NewJoin of the specified type and direction.

func (*Join) On

func (join *Join) On(left TableField, comparison Comparison, right interface{}) *ConditionExpression

On specifies the the conditions of a join based upon two fields or a field and a discrete value

func (*Join) SQL

func (join *Join) SQL() (string, []interface{})

SQL that represents this join.

type JoinDirection

type JoinDirection string

JoinDirection left or right

type JoinError

type JoinError struct {
	// contains filtered or unexported fields
}

JoinError signifying a problem with the created join.

func (*JoinError) Error

func (err *JoinError) Error() string

type JoinType

type JoinType string

JoinType inner or outer

type MissingTablesError

type MissingTablesError struct {
	Tables []string
	// contains filtered or unexported fields
}

MissingTablesError is returned when column's are being used from a table that is not part of the query.

func (*MissingTablesError) Error

func (err *MissingTablesError) Error() string

func (*MissingTablesError) Trace

func (err *MissingTablesError) Trace() []string

Trace returns the stack trace for the error

type OrderDirection

type OrderDirection string

OrderDirection for use in an order by Ascending or Descending

type SelectExpression

type SelectExpression interface {
	// GetName that can be used to reference this expression
	GetName() string
	// GetTables that are used in this expression
	GetTables() []string
	// SQL that represents this SelectExpression
	SQL() string
}

SelectExpression for use in identifying the fields desired in a select query.

func Alias

func Alias(tableField TableField, aliasName string) SelectExpression

Alias the passed table field for use in or as a SelectExpression

func Coalesce

func Coalesce(column TableField, defaultValue string, alias string) SelectExpression

Coalesce creates a SQL coalesce that can be used as a SelectExpression

func NotNull

func NotNull(tableField TableField, alias string) SelectExpression

NotNull field for use as a select expression

type SelectQuery

type SelectQuery struct {
	Seperator string
	// contains filtered or unexported fields
}

SelectQuery for retrieving data from a database table.

func Select

func Select(selectExpressions ...SelectExpression) *SelectQuery

Select creates a new select query based on the passed expressions for the select clause.

func SelectDistinct

func SelectDistinct(selectExpressions ...SelectExpression) *SelectQuery

SelectDistinct creates a new select query based on the passed expressions for the select clause with a distinct modifier.

func (*SelectQuery) From

func (q *SelectQuery) From(table Table) *SelectQuery

From sets the primary table the query will get values from.

func (*SelectQuery) GetAlias

func (q *SelectQuery) GetAlias(tableName string) string

GetAlias of the passed table name in this query.

func (*SelectQuery) GroupBy

func (q *SelectQuery) GroupBy(expressions ...SelectExpression) *SelectQuery

GroupBy the passed table field.

func (*SelectQuery) InnerJoin

func (q *SelectQuery) InnerJoin(table Table) *Join

InnerJoin with another table in the database.

func (*SelectQuery) OrderBy

func (q *SelectQuery) OrderBy(field TableField, direction OrderDirection) *SelectQuery

OrderBy the passed field and direction.

func (*SelectQuery) OuterJoin

func (q *SelectQuery) OuterJoin(direction JoinDirection, table Table) *Join

OuterJoin with another table in the database.

func (*SelectQuery) SQL

func (q *SelectQuery) SQL(limit, offset uint) (string, []interface{}, error)

SQL statement corresponding to this query.

func (*SelectQuery) SelectFrom added in v1.2.3

func (q *SelectQuery) SelectFrom(selectExpressions ...SelectExpression) *SelectQuery

SelectFrom this query but with different select expressions, not a deep copy

func (*SelectQuery) Validate

func (q *SelectQuery) Validate() bool

Validate that this query can be executed.

func (*SelectQuery) Where

func (q *SelectQuery) Where(condition *ConditionExpression) *SelectQuery

Where the comparison between the two tablefields evaluates to true.

type Table

type Table interface {
	// GetName returns the name of the database table
	GetName() string
	// GetAlias returns the alias of the database table to be used in the query
	GetAlias() string
	// PrimaryKey returns the primary key TableField
	PrimaryKey() TableField
	// AllColumns returns the AllColumns TableField for this Table
	AllColumns() TableField
	// ReadColumns returns the default set of columns for a read operation
	ReadColumns() []TableField
	// WriteColumns returns the default set of columns for a write operation
	WriteColumns() []TableField
	// SortBy returns the name of the default sort by field
	SortBy() (TableField, OrderDirection)
}

Table represents a db table

type TableField

type TableField struct {
	// Name of the column in the database table
	Name string
	// Table that the column is on
	Table string
}

TableField represents a single column on a table.

func (TableField) Equal

func (tf TableField) Equal(obj interface{}) *ConditionExpression

Equal returns a condition expression for this table field Equal to the passed obj.

func (TableField) GetName

func (tf TableField) GetName() string

GetName that can be used to reference this expression

func (TableField) GetTables

func (tf TableField) GetTables() []string

GetTables that are used in this expression

func (TableField) GreaterThan

func (tf TableField) GreaterThan(obj interface{}) *ConditionExpression

GreaterThan returns a condition expression for this table field GreaterThan to the passed obj.

func (TableField) GreaterThanEqual

func (tf TableField) GreaterThanEqual(obj interface{}) *ConditionExpression

GreaterThanEqual returns a condition expression for this table field GreaterThanEqual to the passed obj.

func (TableField) In

func (tf TableField) In(objs ...interface{}) *ConditionExpression

In returns a condition expression for this table field in to the passed objs.

func (TableField) IsNotNull

func (tf TableField) IsNotNull() *ConditionExpression

IsNotNull returns a condition expression for this table field where it is not NULL

func (TableField) IsNull

func (tf TableField) IsNull() *ConditionExpression

IsNull returns a condition expression for this table field when it is NULL

func (TableField) LessThan

func (tf TableField) LessThan(obj interface{}) *ConditionExpression

LessThan returns a condition expression for this table field LessThan to the passed obj.

func (TableField) LessThanEqual

func (tf TableField) LessThanEqual(obj interface{}) *ConditionExpression

LessThanEqual returns a condition expression for this table field LessThanEqual to the passed obj.

func (TableField) Like added in v1.3.4

func (tf TableField) Like(obj interface{}) *ConditionExpression

Like returns a condition expression for this table field Like to the passed obj.

func (TableField) NotEqual

func (tf TableField) NotEqual(obj interface{}) *ConditionExpression

NotEqual returns a condition expression for this table field NotEqual to the passed obj.

func (TableField) NullSafeEqual

func (tf TableField) NullSafeEqual(obj interface{}) *ConditionExpression

NullSafeEqual returns a condition expression for this table field NullSafeEqual to the passed obj.

func (TableField) SQL

func (tf TableField) SQL() string

SQL that represents this table field

type UpdateQuery

type UpdateQuery struct {
	// contains filtered or unexported fields
}

UpdateQuery represents a query to update rows in a database Currently only supports single table, to change this the tableReference would have to be built out more.

func Update

func Update(table Table) *UpdateQuery

Update returns a query that can be used for updating rows in the passed table.

func (*UpdateQuery) GetAlias

func (q *UpdateQuery) GetAlias(tableName string) string

GetAlias returns the alias for the passed tablename used in this query.

func (*UpdateQuery) OrderBy

func (q *UpdateQuery) OrderBy(field TableField, direction OrderDirection) *UpdateQuery

OrderBy the passed field and direction.

func (*UpdateQuery) ParameterizedSQL

func (q *UpdateQuery) ParameterizedSQL(limit int) (string, error)

ParameterizedSQL representation of this query.

func (*UpdateQuery) SQL

func (q *UpdateQuery) SQL(limit int) (string, []interface{}, error)

SQL representation of this query.

func (*UpdateQuery) Set

func (q *UpdateQuery) Set(field TableField, value interface{}) *UpdateQuery

Set adds a assignment to this update query.

func (*UpdateQuery) SetParam

func (q *UpdateQuery) SetParam(field TableField) *UpdateQuery

SetParam adds a parameterized assignment to this update query.

func (*UpdateQuery) Where

func (q *UpdateQuery) Where(condition *ConditionExpression) *UpdateQuery

Where determines the conditions by which the assignments in this query apply

type ValidationFromNotSetError

type ValidationFromNotSetError struct {
	// contains filtered or unexported fields
}

ValidationFromNotSetError is set on the query when From has not been called on this query.

func (*ValidationFromNotSetError) Error

func (err *ValidationFromNotSetError) Error() string

func (*ValidationFromNotSetError) Trace

func (err *ValidationFromNotSetError) Trace() []string

Trace returns the stack trace for the error

Jump to

Keyboard shortcuts

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