orm

package
v1.1.47 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

Constant Boolean connection operations

View Source
const (
	Equals             = "="
	NotEqual           = "<>"
	GreaterThan        = ">"
	GreaterThanEqualTo = ">="
	LessThan           = "<"
	LessThanEqualTo    = "<="
	Like               = "LIKE"
)

Constant comparison operations

View Source
const (
	All = "*"
)

SQL constants

Variables

This section is empty.

Functions

This section is empty.

Types

type ConstantQueryTerm

type ConstantQueryTerm[T any] struct {
	Name     string
	Operator string
	Value    string
}

ConstantQueryTerm contains the functionality allowing the user to compare a database field to a concrete value

func NewConstantQueryTerm

func NewConstantQueryTerm[T any](name string, op string, value string) *ConstantQueryTerm[T]

NewConstantQueryTerm creates a new constant query term from the field name, the comparison operation and a value to which the field should be compared

func (*ConstantQueryTerm[T]) ModifyQuery

func (term *ConstantQueryTerm[T]) ModifyQuery(query *Query[T])

ModifyQuery modifies the query to include this query term

type FunctionCallQueryTerm added in v1.1.43

type FunctionCallQueryTerm[T any] 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[T any](call string, args ...any) *FunctionCallQueryTerm[T]

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

func (*FunctionCallQueryTerm[T]) ModifyQuery added in v1.1.43

func (term *FunctionCallQueryTerm[T]) ModifyQuery(query *Query[T])

ModifyQuery modifies the query to include this query term

type InjectedQueryTerm

type InjectedQueryTerm[T any] struct {
	Name     string
	Operator string
	Value    any
}

InjectedQueryTerm creates a new query term that injects an argument into the query's arguments list and a placeholder ? into the query string itself. This is intended for variables that need to be added to SQL queries, thereby avoiding the possibility of SQL injection

func NewInjectedQueryTerm

func NewInjectedQueryTerm[T any](name string, op string, value any) *InjectedQueryTerm[T]

NewInjectedQueryTerm creates a new injected query term from a field name, a comparison operation, and a value to which the field should be compared, to be injected later

func (*InjectedQueryTerm[T]) ModifyQuery

func (term *InjectedQueryTerm[T]) ModifyQuery(query *Query[T])

ModifyQuery modifies the query to include this query term

type MultiQueryTerm

type MultiQueryTerm[T any] struct {
	Operator string
	Inner    []WhereClause[T]
}

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[T any](op string, terms ...WhereClause[T]) *MultiQueryTerm[T]

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

func (*MultiQueryTerm[T]) ModifyQuery

func (term *MultiQueryTerm[T]) ModifyQuery(query *Query[T])

ModifyQuery modifies the query to include this query term

type Query

type Query[T any] struct {
	// contains filtered or unexported fields
}

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

func NewQuery

func NewQuery[T any](logger *utils.Logger) *Query[T]

NewQuery creates a new Query from a logger with default values

func (*Query[T]) From

func (query *Query[T]) From(table string) *Query[T]

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[T]) FromQuery added in v1.1.46

func (query *Query[T]) FromQuery(inner *Query[T]) *Query[T]

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[T]) GroupBy

func (query *Query[T]) GroupBy(fields ...string) *Query[T]

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[T]) Limit added in v1.1.47

func (query *Query[T]) Limit(limit uint) *Query[T]

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

func (*Query[T]) Offset added in v1.1.47

func (query *Query[T]) Offset(offset uint) *Query[T]

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

func (*Query[T]) OrderBy

func (query *Query[T]) OrderBy(fields ...string) *Query[T]

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[T]) Run

func (query *Query[T]) Run(ctx context.Context, db *sql.DB) ([]*T, error)

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

func (*Query[T]) Select

func (query *Query[T]) Select(fields ...string) *Query[T]

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[T]) String

func (query *Query[T]) String() string

String converts a Query to its string equivalent

func (*Query[T]) Where

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

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 cahined with other functions.

type WhereClause

type WhereClause[T any] interface {
	ModifyQuery(*Query[T])
}

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

Jump to

Keyboard shortcuts

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