queries

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 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 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 FuncExpr

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

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

It can be used like so:

	FuncExpr{
		// 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 (*FuncExpr) And

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

func (*FuncExpr) Args

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

func (*FuncExpr) Clone

func (e *FuncExpr) Clone() Expression

func (*FuncExpr) IsNot

func (e *FuncExpr) IsNot() bool

func (*FuncExpr) Not

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

func (*FuncExpr) Or

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

func (*FuncExpr) SQL

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

func (*FuncExpr) With

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

type LogicalOp

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

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() ([]T, error)

func (*QuerySet[T]) Clone

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

func (*QuerySet[T]) Count

func (qs *QuerySet[T]) Count() (int, error)

func (*QuerySet[T]) Fields

func (qs *QuerySet[T]) Fields(fields ...string) *QuerySet[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() (T, error)

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]) 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]) Union

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

type Union

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

Jump to

Keyboard shortcuts

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