orm

package
v1.1.58 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: Unlicense Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	All  = "*"
	Null = "NULL"
)

SQL constants

View Source
const (
	And = "AND"
	Or  = "OR"
)

Constant Boolean connection operations

Variables

This section is empty.

Functions

func RunQuery added in v1.1.48

func RunQuery[TReturn any, TStatement Statement](ctx context.Context, query TStatement, db *sql.DB,
	logger *utils.Logger) ([]*TReturn, error)

Run runs the query against a provided database connection, returning the query results

Types

type Argument added in v1.1.48

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

Argument contains the data used to inject a variable parameter into an SQL query

func NewArgument added in v1.1.48

func NewArgument(value any) *Argument

NewArgument creates a new SQL argument from the variable that should be injected.

func (*Argument) ModifyQuery added in v1.1.48

func (a *Argument) ModifyQuery(query *Query) string

ModifyQuery modifies the query, returning the string value of the parameter.

type Constant added in v1.1.48

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

Constant contains the data used to serialize a constant parameter in an SQL query

func NewConstant added in v1.1.48

func NewConstant(value driver.Value, args ...any) *Constant

NewConstant creates a new constant parameter from a driver.Value and a list of arguments used to convert the value to a string. For strings, no additional arguments are accepted. For a time.Time, the optional arguments conform to the Format function. For integers and unsigned integeters, the optional arguments will conform to those submitted to strconv.FormatInt or strconv.FormatUint respectively. For floating-point values, the optional arguments conform to strconv.FormatFloat except for the size parameter, which will be decided based on the value submitted to the function. Boolean values will be converted to TRUE or FALSE depending on the value of the parameter. No other types will be accepted.

func (*Constant) ModifyQuery added in v1.1.48

func (c *Constant) ModifyQuery(query *Query) string

ModifyQuery modifies the query, returning the string value of the parameter.

type FunctionCallQueryTerm added in v1.1.43

type FunctionCallQueryTerm struct {
	Call      string
	Arguments []any
}

FunctionCallQueryTerm creates a new function call query term that allows the user to inject an SQL function call into the WHERE clause of an SQL query

func NewFunctionCallQueryTerm added in v1.1.43

func NewFunctionCallQueryTerm(call string, args ...any) *FunctionCallQueryTerm

NewFunctionCallQueryTerm creates a new function call query term from a function name and arguments

func (*FunctionCallQueryTerm) ModifyQuery added in v1.1.43

func (term *FunctionCallQueryTerm) ModifyQuery(query *Query) string

ModifyQuery modifies the query to include this query term

type Keyword added in v1.1.57

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

Keyword is a parameter that is an SQL keyword, such as NULL or TRUE

func NewKeyword added in v1.1.57

func NewKeyword(value string) *Keyword

NewKeyword creates a new keyword parameter from a string value

func (*Keyword) ModifyQuery added in v1.1.57

func (k *Keyword) ModifyQuery(query *Query) string

ModifyQuery modifies the query, returning the string value of the parameter.

type MultiQueryTerm

type MultiQueryTerm struct {
	Operator string
	Inner    []WhereClause
}

MultiQueryTerm creates a new query term that allows multiple query terms to be joined together inside a set of parentheses. This is intended to allow for alternating sets of AND/OR logic (i.e. A AND (B OR C))

func NewMultiQueryTerm

func NewMultiQueryTerm(op string, terms ...WhereClause) *MultiQueryTerm

NewMultiQueryTerm creates a new multi-query term from a connecting operator and a list of inner terms

func (*MultiQueryTerm) ModifyQuery

func (term *MultiQueryTerm) ModifyQuery(query *Query) string

ModifyQuery modifies the query to include this query term

type Parameter added in v1.1.48

type Parameter interface {
	ModifyQuery(*Query) string
}

Parameter describes the functionality that should exist for parameter terms

type ProcedureCall added in v1.1.49

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

ProcedureCall contains the functionality necessary to describe calls to SQL stored procedures

func NewProcedureCall added in v1.1.49

func NewProcedureCall(name string, args ...any) *ProcedureCall

NewProcedureCall creates a new procedure call from a name and a list of arguments

func (*ProcedureCall) Arguments added in v1.1.49

func (call *ProcedureCall) Arguments() []any

Arguments returns the arguments that should be injected into the ProcedureCall

func (*ProcedureCall) Source added in v1.1.49

func (call *ProcedureCall) Source() string

Source returns the source of the ProcedureCall, i.e. its procedure name

func (*ProcedureCall) String added in v1.1.49

func (call *ProcedureCall) String() string

String converts a ProcedureCall to its string equivalent

type Query

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

Query allows for the creation of execution of SQL queries in a programmatic manner

func NewQuery

func NewQuery() *Query

NewQuery creates a new Query from a logger with default values

func (*Query) Arguments added in v1.1.49

func (query *Query) Arguments() []any

Arguments returns the arguments that should be injected into the Query

func (*Query) From

func (query *Query) From(table string) *Query

From sets the table that data should be pulled from, returning the modified query so that this function can be chained with others

func (*Query) FromQuery added in v1.1.46

func (query *Query) FromQuery(inner *Query) *Query

FromQuery sets the table that the data should be pulled from so that it is the results of an inner query. This function returns the modified query so that it can be chained with others

func (*Query) GroupBy

func (query *Query) GroupBy(fields ...string) *Query

GroupBy sets the fields that rows should be grouped by, returning the modified query so that this function can be chained with others

func (*Query) Having added in v1.1.50

func (query *Query) Having(op string, clauses ...WhereClause) *Query

Having sets the having filter clauses that should be used to determine which rows are returned from the query. The op variable should be either AND or OR and is used to chain the clauses together. This function returns the modified query so that it can be chained with other functions.

func (*Query) Limit added in v1.1.47

func (query *Query) Limit(limit any, constant bool) *Query

Limit sets the limit on the number of rows that may be returned by the query

func (*Query) Offset added in v1.1.47

func (query *Query) Offset(offset any, constant bool) *Query

Offset sets the offset on the number of rows that should be skipped before being returned by the query

func (*Query) OrderBy

func (query *Query) OrderBy(fields ...string) *Query

OrderBy sets the fields that rows should be sorted by, returning the modified query so that this function can be chained with others

func (*Query) Select

func (query *Query) Select(fields ...string) *Query

Select determines which fields should be selected in the query, returning the modified query so that this function can be chained with others

func (*Query) Source added in v1.1.49

func (query *Query) Source() string

Source returns the source of the Query, i.e. its table name

func (*Query) String

func (query *Query) String() string

String converts a Query to its string equivalent

func (*Query) Where

func (query *Query) Where(op string, clauses ...WhereClause) *Query

Where sets the filter clauses that should be used to determine which rows are returned from the query. The op variable should be either AND or OR and is used to chain the clauses together. This function returns the modified query so that it can be chained with other functions.

type QueryTerm added in v1.1.48

type QueryTerm struct {
	Name     string
	Operator string
	Value    Parameter
}

QueryTerm is the base where clause that allows a single field-parameter comparison

func NewQueryTerm added in v1.1.48

func NewQueryTerm(name string, op string, param Parameter) *QueryTerm

NewQueryTerm creates a new QueryTerm from a name, operation and parameter

func (*QueryTerm) ModifyQuery added in v1.1.48

func (term *QueryTerm) ModifyQuery(query *Query) string

ModifyQuery modifies the query to include this query term

type Statement added in v1.1.49

type Statement interface {

	// Source describes what resource the statement is being executed against
	Source() string

	// String returns the string representation of the statement
	String() string

	// Arguments returns the list of arguments that should be injected with the statement
	Arguments() []any
}

Statement describes the functionality that should be associated with an SQL-executable statement

type UnaryQueryTerm added in v1.1.48

type UnaryQueryTerm struct {
	Operator string
	Clause   WhereClause
}

UnaryQueryTerm creates a new query term that allows a single query term to be combined with a unary operator

func NewUnaryQueryTerm added in v1.1.48

func NewUnaryQueryTerm(op string, clause WhereClause) *UnaryQueryTerm

NewUnaryQueryTerm creates a new unary query term from an operator and an inner where clause

func (*UnaryQueryTerm) ModifyQuery added in v1.1.48

func (term *UnaryQueryTerm) ModifyQuery(query *Query) string

ModifyQuery modifies the query to include this query term

type WhereClause

type WhereClause interface {
	ModifyQuery(*Query) string
}

WhereClause describes the functionality that should exist in any where clause terms

func Between added in v1.1.48

func Between[T any](field string, lower T, lowerConst bool, upper T, upperConst bool) WhereClause

Between creates a new where clause stating that a field is between two values

func Equals

func Equals(field string, value any, constant bool) WhereClause

Equals creates a new where clause stating that a field is equal to a parameter

func GreaterThan

func GreaterThan(field string, value any, constant bool) WhereClause

GreaterThan creates a new where clause stating that a field is greater than a parameter

func GreaterThanOrEqualTo added in v1.1.48

func GreaterThanOrEqualTo(field string, value any, constant bool) WhereClause

GreaterThanOrEqualTo creates a new where clause stating that a field is greater than or equal to a parameter

func IsNull added in v1.1.57

func IsNull(field string) WhereClause

IsNull creates a new where clause asserting that a field is null

func LessThan

func LessThan(field string, value any, constant bool) WhereClause

LessThan creates a new where clause stating that a field is less than a parameter

func LessThanOrEqualTo added in v1.1.48

func LessThanOrEqualTo(field string, value any, constant bool) WhereClause

LessThanOrEqualTo creates a new where clause stating that a field is less than or equal to a parameter

func Like

func Like(field string, value any, constant bool) WhereClause

Like creates a new where clause stating that a field should be compared to a value using the LIKE keyword

func Not added in v1.1.48

func Not(clause WhereClause) WhereClause

Not creates a new where clause negating the clause sent to it as a parameter

func NotEquals added in v1.1.48

func NotEquals(field string, value any, constant bool) WhereClause

NotEquals creates a new where clause stating that a field is not equal to a parameter

func NotNull added in v1.1.57

func NotNull(field string) WhereClause

NotNull creates a new where clause asserting that a field is not null

Jump to

Keyboard shortcuts

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