queries

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2025 License: GPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNoDatabase    errs.Error = "No database connection"
	ErrUnknownDriver errs.Error = "Unknown driver"
	ErrNoTableName   errs.Error = "No table name"
	ErrFieldNull     errs.Error = "Field cannot be null"
	ErrLastInsertId  errs.Error = "Last insert id is not valid"
)

Variables

View Source
var Quote = "`"

Functions

func CT_GetObject

func CT_GetObject[T attrs.Definer](identifier any) (interface{}, error)

func CT_ListObjects

func CT_ListObjects[T attrs.Definer](amount, offset uint) ([]interface{}, error)

func CT_ListObjectsByIDs

func CT_ListObjectsByIDs[T attrs.Definer](i []interface{}) ([]interface{}, error)

func CountObjects

func CountObjects[T attrs.Definer](obj T) (int64, error)

func CreateObject

func CreateObject[T attrs.Definer](obj T) error

func DeleteObject

func DeleteObject[T attrs.Definer](obj T) error

func GetObject

func GetObject[T attrs.Definer](identifier any) (T, error)

func ListObjects

func ListObjects[T attrs.Definer](offset, limit uint64, ordering ...string) ([]T, error)

func ListObjectsByIDs

func ListObjectsByIDs[T attrs.Definer, T2 any](offset, limit uint64, ids []T2) ([]T, error)

func RegisterDriver added in v1.0.2

func RegisterDriver(driver driver.Driver, database string)

RegisterDriver registers a driver with the given database name.

This is used to determine the database type when using sqlx.

If your driver is not one of: - github.com/go-sql-driver/mysql.MySQLDriver - github.com/mattn/go-sqlite3.SQLiteDriver - github.com/jackc/pgx/v5/stdlib.Driver

Then it explicitly needs to be registered here.

func SaveObject

func SaveObject[T attrs.Definer](obj T) error

func UpdateObject

func UpdateObject[T attrs.Definer](obj T) error

Types

type CountQuery added in v1.0.3

type CountQuery[T any] Query[int64, T]

type ExistsQuery added in v1.0.3

type ExistsQuery[T any] Query[bool, T]

type ExprGroup

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

ExprGroup

func (*ExprGroup) And

func (g *ExprGroup) And(exprs ...Expression) Expression

func (*ExprGroup) Args

func (g *ExprGroup) Args() []any

func (*ExprGroup) Clone

func (g *ExprGroup) Clone() Expression

func (*ExprGroup) IsNot

func (g *ExprGroup) IsNot() bool

func (*ExprGroup) Not

func (g *ExprGroup) Not(not bool) Expression

func (*ExprGroup) Or

func (g *ExprGroup) Or(exprs ...Expression) Expression

func (*ExprGroup) SQL

func (g *ExprGroup) SQL(sb *strings.Builder)

func (*ExprGroup) With

func (g *ExprGroup) With(m attrs.Definer, quote string) Expression

type ExprNode

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

func Expr

func Expr(field string, operation string, value ...any) *ExprNode

func Q

func Q(fieldLookup string, value ...any) *ExprNode

func (*ExprNode) And

func (e *ExprNode) And(exprs ...Expression) Expression

func (*ExprNode) Args

func (e *ExprNode) Args() []any

func (*ExprNode) Clone

func (e *ExprNode) Clone() Expression

func (*ExprNode) IsNot

func (e *ExprNode) IsNot() bool

func (*ExprNode) Not

func (e *ExprNode) Not(not bool) Expression

func (*ExprNode) Or

func (e *ExprNode) Or(exprs ...Expression) Expression

func (*ExprNode) SQL

func (e *ExprNode) SQL(sb *strings.Builder)

func (*ExprNode) With

func (e *ExprNode) With(m attrs.Definer, quote string) Expression

type Expression

type Expression interface {
	SQL(sb *strings.Builder)
	Args() []any
	IsNot() bool
	Not(b bool) Expression
	And(...Expression) Expression
	Or(...Expression) Expression
	Clone() Expression
	With(model attrs.Definer, quote string) Expression
}

func And

func And(exprs ...Expression) Expression

func Or

func Or(exprs ...Expression) Expression

type FieldInfo added in v1.0.3

type FieldInfo struct {
	SourceField attrs.Field
	Model       attrs.Definer
	Table       string
	Chain       []string
	Fields      []attrs.Field
}

type JoinDef added in v1.0.3

type JoinDef struct {
	Table      string
	TypeJoin   string
	ConditionA string
	Logic      string
	ConditionB string
}

type LogicalOp

type LogicalOp string
const (
	OpAnd LogicalOp = "AND"
	OpOr  LogicalOp = "OR"
)

type OrderBy added in v1.0.3

type OrderBy struct {
	Table string
	Field string
	Desc  bool
}

type Query added in v1.0.3

type Query[T1 any, T2 any] interface {
	SQL() string
	Args() []any
	Model() T2
	Exec() (T1, error)
}

type QuerySet

type QuerySet[T attrs.Definer] struct {
	// contains filtered or unexported fields
}

func Objects

func Objects[T attrs.Definer](model T) *QuerySet[T]

func (*QuerySet[T]) All

func (qs *QuerySet[T]) All() Query[[]T, T]

func (*QuerySet[T]) Clone

func (qs *QuerySet[T]) Clone() *QuerySet[T]

func (*QuerySet[T]) Count

func (qs *QuerySet[T]) Count() CountQuery[T]

func (*QuerySet[T]) Delete added in v1.0.3

func (qs *QuerySet[T]) Delete() CountQuery[T]

func (*QuerySet[T]) Distinct added in v1.0.3

func (qs *QuerySet[T]) Distinct() *QuerySet[T]

func (*QuerySet[T]) Exists added in v1.0.3

func (qs *QuerySet[T]) Exists() ExistsQuery[T]

func (*QuerySet[T]) Filter

func (qs *QuerySet[T]) Filter(key interface{}, vals ...interface{}) *QuerySet[T]

func (*QuerySet[T]) First

func (qs *QuerySet[T]) First() Query[T, T]

func (*QuerySet[T]) ForUpdate

func (qs *QuerySet[T]) ForUpdate() *QuerySet[T]

func (*QuerySet[T]) GroupBy

func (qs *QuerySet[T]) GroupBy(fields ...string) *QuerySet[T]

func (*QuerySet[T]) Having

func (qs *QuerySet[T]) Having(key interface{}, vals ...interface{}) *QuerySet[T]

func (*QuerySet[T]) Last added in v1.0.3

func (qs *QuerySet[T]) Last() Query[T, T]

func (*QuerySet[T]) Limit

func (qs *QuerySet[T]) Limit(n int) *QuerySet[T]

func (*QuerySet[T]) Offset

func (qs *QuerySet[T]) Offset(n int) *QuerySet[T]

func (*QuerySet[T]) OrderBy

func (qs *QuerySet[T]) OrderBy(fields ...string) *QuerySet[T]

func (*QuerySet[T]) Reverse added in v1.0.3

func (qs *QuerySet[T]) Reverse() *QuerySet[T]

func (*QuerySet[T]) Select added in v1.0.3

func (qs *QuerySet[T]) Select(fields ...string) *QuerySet[T]

func (*QuerySet[T]) Union

func (qs *QuerySet[T]) Union(f func(*QuerySet[attrs.Definer])) *QuerySet[T]

func (*QuerySet[T]) Update added in v1.0.3

func (qs *QuerySet[T]) Update(value T) CountQuery[T]

func (*QuerySet[T]) ValuesList added in v1.0.3

func (qs *QuerySet[T]) ValuesList(fields ...string) ValuesListQuery[T]

type RawExpr added in v1.0.3

type RawExpr struct {
	Statement string
	Fields    []string
	Params    []any
	// contains filtered or unexported fields
}

RawExpr is a function expression for SQL queries. It is used to represent a function call in SQL queries.

It can be used like so:

	RawExpr{
		// Represent the SQL function call, with each %s being replaced by the corresponding field in fields.
		sql:    `SUBSTR(TRIM(%s, " "), 0, 2) = ?``,
     	// The fields to be used in the SQL function call. Each field will be replaced by the corresponding value in args.
		fields: []string{"myField"},
		// The arguments to be used in the SQL function call. Each argument will be replaced by the corresponding value in args.
		args:   []any{"ab"},
	}

func (*RawExpr) And added in v1.0.3

func (e *RawExpr) And(exprs ...Expression) Expression

func (*RawExpr) Args added in v1.0.3

func (e *RawExpr) Args() []any

func (*RawExpr) Clone added in v1.0.3

func (e *RawExpr) Clone() Expression

func (*RawExpr) IsNot added in v1.0.3

func (e *RawExpr) IsNot() bool

func (*RawExpr) Not added in v1.0.3

func (e *RawExpr) Not(not bool) Expression

func (*RawExpr) Or added in v1.0.3

func (e *RawExpr) Or(exprs ...Expression) Expression

func (*RawExpr) SQL added in v1.0.3

func (e *RawExpr) SQL(sb *strings.Builder)

func (*RawExpr) With added in v1.0.3

func (e *RawExpr) With(m attrs.Definer, quote string) Expression

type Union

type Union func(*QuerySet[attrs.Definer])

type ValuesListQuery added in v1.0.3

type ValuesListQuery[T any] Query[[][]any, T]

Jump to

Keyboard shortcuts

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