Documentation
¶
Index ¶
- Constants
- func CT_GetObject[T attrs.Definer](identifier any) (interface{}, error)
- func CT_ListObjects[T attrs.Definer](amount, offset uint) ([]interface{}, error)
- func CT_ListObjectsByIDs[T attrs.Definer](i []interface{}) ([]interface{}, error)
- func CountObjects[T attrs.Definer](obj T) (int64, error)
- func CreateObject[T attrs.Definer](obj T) error
- func DefinerListToList[T attrs.Definer](list []attrs.Definer) []T
- func DeleteObject[T attrs.Definer](obj T) (int64, error)
- func GetObject[T attrs.Definer](identifier any) (T, error)
- func ListObjects[T attrs.Definer](offset, limit uint64, ordering ...string) ([]T, error)
- func ListObjectsByIDs[T attrs.Definer, T2 any](offset, limit uint64, ids []T2) ([]T, error)
- func RegisterCompiler(driver driver.Driver, compiler func(model attrs.Definer) QueryCompiler)
- func RegisterDriver(driver driver.Driver, database string, supportsReturning ...SupportsReturning)
- func RegisterLookup(lookup string, ...)
- func SaveObject[T attrs.Definer](obj T) error
- func UpdateObject[T attrs.Definer](obj T) (int64, error)
- type CountQuery
- type DB
- type ErrorQuery
- type ExistsQuery
- type ExprGroup
- func (g *ExprGroup) And(exprs ...Expression) Expression
- func (g *ExprGroup) Args() []any
- func (g *ExprGroup) Clone() Expression
- func (g *ExprGroup) IsNot() bool
- func (g *ExprGroup) Not(not bool) Expression
- func (g *ExprGroup) Or(exprs ...Expression) Expression
- func (g *ExprGroup) SQL(sb *strings.Builder)
- func (g *ExprGroup) With(d driver.Driver, m attrs.Definer, quote string) Expression
- type ExprNode
- func (e *ExprNode) And(exprs ...Expression) Expression
- func (e *ExprNode) Args() []any
- func (e *ExprNode) Clone() Expression
- func (e *ExprNode) IsNot() bool
- func (e *ExprNode) Not(not bool) Expression
- func (e *ExprNode) Or(exprs ...Expression) Expression
- func (e *ExprNode) SQL(sb *strings.Builder)
- func (e *ExprNode) With(d driver.Driver, m attrs.Definer, quote string) Expression
- type Expression
- type FieldInfo
- type GenericQueryBuilder
- func (g *GenericQueryBuilder) BuildCountQuery(ctx context.Context, qs *QuerySet, where []Expression, joins []JoinDef, ...) CountQuery
- func (g *GenericQueryBuilder) BuildCreateQuery(ctx context.Context, qs *QuerySet, fields FieldInfo, primary attrs.Field, ...) Query[[]interface{}]
- func (g *GenericQueryBuilder) BuildDeleteQuery(ctx context.Context, qs *QuerySet, where []Expression, joins []JoinDef, ...) CountQuery
- func (g *GenericQueryBuilder) BuildSelectQuery(ctx context.Context, qs *QuerySet, fields []FieldInfo, where []Expression, ...) Query[[][]interface{}]
- func (g *GenericQueryBuilder) BuildUpdateQuery(ctx context.Context, qs *QuerySet, fields FieldInfo, where []Expression, ...) CountQuery
- func (g *GenericQueryBuilder) CommitTransaction() error
- func (g *GenericQueryBuilder) DB() DB
- func (g *GenericQueryBuilder) InTransaction() bool
- func (g *GenericQueryBuilder) Quote() (string, string)
- func (g *GenericQueryBuilder) RollbackTransaction() error
- func (g *GenericQueryBuilder) StartTransaction(ctx context.Context) (Transaction, error)
- func (g *GenericQueryBuilder) SupportsReturning() SupportsReturning
- type JoinDef
- type LogicalOp
- type OrderBy
- type Query
- type QueryCompiler
- type QueryObject
- type QuerySet
- func (qs *QuerySet) All() Query[[]attrs.Definer]
- func (qs *QuerySet) Clone() *QuerySet
- func (qs *QuerySet) Compiler() QueryCompiler
- func (qs *QuerySet) Count() CountQuery
- func (qs *QuerySet) Create(value attrs.Definer) Query[attrs.Definer]
- func (qs *QuerySet) DB() DB
- func (qs *QuerySet) Delete() CountQuery
- func (qs *QuerySet) Distinct() *QuerySet
- func (qs *QuerySet) Exists() ExistsQuery
- func (qs *QuerySet) Filter(key interface{}, vals ...interface{}) *QuerySet
- func (qs *QuerySet) First() Query[attrs.Definer]
- func (qs *QuerySet) ForUpdate() *QuerySet
- func (qs *QuerySet) Get() Query[attrs.Definer]
- func (qs *QuerySet) GetOrCreate(value attrs.Definer) (attrs.Definer, error)
- func (qs *QuerySet) GroupBy(fields ...string) *QuerySet
- func (qs *QuerySet) Having(key interface{}, vals ...interface{}) *QuerySet
- func (qs *QuerySet) Last() Query[attrs.Definer]
- func (qs *QuerySet) Limit(n int) *QuerySet
- func (qs *QuerySet) Model() attrs.Definer
- func (qs *QuerySet) Offset(n int) *QuerySet
- func (qs *QuerySet) OrderBy(fields ...string) *QuerySet
- func (qs *QuerySet) Reverse() *QuerySet
- func (qs *QuerySet) Select(fields ...string) *QuerySet
- func (qs *QuerySet) Union(f func(*QuerySet) *QuerySet) *QuerySet
- func (qs *QuerySet) Update(value attrs.Definer) CountQuery
- func (qs *QuerySet) ValuesList(fields ...string) ValuesListQuery
- type RawExpr
- func (e *RawExpr) And(exprs ...Expression) Expression
- func (e *RawExpr) Args() []any
- func (e *RawExpr) Clone() Expression
- func (e *RawExpr) IsNot() bool
- func (e *RawExpr) Not(not bool) Expression
- func (e *RawExpr) Or(exprs ...Expression) Expression
- func (e *RawExpr) SQL(sb *strings.Builder)
- func (e *RawExpr) With(d driver.Driver, m attrs.Definer, quote string) Expression
- type SupportsReturning
- type Transaction
- type Union
- type ValuesListQuery
Constants ¶
View Source
const ( ErrNoDatabase errs.Error = "No database connection" ErrUnknownDriver errs.Error = "Unknown driver" ErrNoTableName errs.Error = "No table name" ErrNoWhereClause errs.Error = "No where clause in query" ErrFieldNull errs.Error = "Field cannot be null" ErrLastInsertId errs.Error = "Last insert id is not valid" ErrUnsupportedLookup errs.Error = "Unsupported lookup type" ErrNoRows errs.Error = "No rows in result set" ErrMultipleRows errs.Error = "Multiple rows in result set" ErrTransactionStarted errs.Error = "Transaction already started" ErrFailedStartTransaction errs.Error = "Failed to start transaction" ErrNoTransaction errs.Error = "Transaction was not started" )
View Source
const MAX_GET_RESULTS = 21
Variables ¶
This section is empty.
Functions ¶
func CT_ListObjects ¶
func CT_ListObjectsByIDs ¶
func CreateObject ¶
func DefinerListToList ¶ added in v1.0.7
func ListObjects ¶
func ListObjectsByIDs ¶
func RegisterCompiler ¶ added in v1.0.7
func RegisterCompiler(driver driver.Driver, compiler func(model attrs.Definer) QueryCompiler)
func RegisterDriver ¶ added in v1.0.2
func RegisterDriver(driver driver.Driver, database string, supportsReturning ...SupportsReturning)
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 RegisterLookup ¶ added in v1.0.7
func SaveObject ¶
Types ¶
type CountQuery ¶ added in v1.0.3
type ErrorQuery ¶ added in v1.0.7
func (*ErrorQuery[T]) Args ¶ added in v1.0.7
func (e *ErrorQuery[T]) Args() []any
func (*ErrorQuery[T]) Exec ¶ added in v1.0.7
func (e *ErrorQuery[T]) Exec() (T, error)
func (*ErrorQuery[T]) Model ¶ added in v1.0.7
func (e *ErrorQuery[T]) Model() attrs.Definer
func (*ErrorQuery[T]) SQL ¶ added in v1.0.7
func (e *ErrorQuery[T]) SQL() string
type ExistsQuery ¶ added in v1.0.3
type ExprGroup ¶
type ExprGroup struct {
// contains filtered or unexported fields
}
ExprGroup
func (*ExprGroup) And ¶
func (g *ExprGroup) And(exprs ...Expression) Expression
func (*ExprGroup) Clone ¶
func (g *ExprGroup) Clone() Expression
func (*ExprGroup) Not ¶
func (g *ExprGroup) Not(not bool) Expression
func (*ExprGroup) Or ¶
func (g *ExprGroup) Or(exprs ...Expression) Expression
type ExprNode ¶
type ExprNode struct {
// contains filtered or unexported fields
}
func (*ExprNode) And ¶
func (e *ExprNode) And(exprs ...Expression) Expression
func (*ExprNode) Clone ¶
func (e *ExprNode) Clone() Expression
func (*ExprNode) Not ¶
func (e *ExprNode) Not(not bool) Expression
func (*ExprNode) Or ¶
func (e *ExprNode) Or(exprs ...Expression) 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(d driver.Driver, 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 GenericQueryBuilder ¶ added in v1.0.7
type GenericQueryBuilder struct {
// contains filtered or unexported fields
}
func (*GenericQueryBuilder) BuildCountQuery ¶ added in v1.0.7
func (g *GenericQueryBuilder) BuildCountQuery( ctx context.Context, qs *QuerySet, where []Expression, joins []JoinDef, groupBy []FieldInfo, limit int, offset int, ) CountQuery
func (*GenericQueryBuilder) BuildCreateQuery ¶ added in v1.0.7
func (*GenericQueryBuilder) BuildDeleteQuery ¶ added in v1.0.7
func (g *GenericQueryBuilder) BuildDeleteQuery( ctx context.Context, qs *QuerySet, where []Expression, joins []JoinDef, groupBy []FieldInfo, ) CountQuery
func (*GenericQueryBuilder) BuildSelectQuery ¶ added in v1.0.7
func (*GenericQueryBuilder) BuildUpdateQuery ¶ added in v1.0.7
func (g *GenericQueryBuilder) BuildUpdateQuery( ctx context.Context, qs *QuerySet, fields FieldInfo, where []Expression, joins []JoinDef, groupBy []FieldInfo, values []any, ) CountQuery
func (*GenericQueryBuilder) CommitTransaction ¶ added in v1.0.7
func (g *GenericQueryBuilder) CommitTransaction() error
func (*GenericQueryBuilder) DB ¶ added in v1.0.7
func (g *GenericQueryBuilder) DB() DB
func (*GenericQueryBuilder) InTransaction ¶ added in v1.0.7
func (g *GenericQueryBuilder) InTransaction() bool
func (*GenericQueryBuilder) Quote ¶ added in v1.0.7
func (g *GenericQueryBuilder) Quote() (string, string)
func (*GenericQueryBuilder) RollbackTransaction ¶ added in v1.0.7
func (g *GenericQueryBuilder) RollbackTransaction() error
func (*GenericQueryBuilder) StartTransaction ¶ added in v1.0.7
func (g *GenericQueryBuilder) StartTransaction(ctx context.Context) (Transaction, error)
func (*GenericQueryBuilder) SupportsReturning ¶ added in v1.0.7
func (g *GenericQueryBuilder) SupportsReturning() SupportsReturning
type QueryCompiler ¶ added in v1.0.7
type QueryCompiler interface {
// DB returns the database connection used by the query compiler.
//
// If a transaction was started, it will return the transaction instead of the database connection.
DB() DB
// Quote returns the quotes used by the database.
//
// This is used to quote table and field names.
// For example, MySQL uses backticks (`) and PostgreSQL uses double quotes (").
Quote() (front string, back string)
// SupportsReturning returns the type of returning supported by the database.
// It can be one of the following:
//
// - SupportsReturningNone: no returning supported
// - SupportsReturningLastInsertId: last insert id supported
// - SupportsReturningColumns: returning columns supported
SupportsReturning() SupportsReturning
// StartTransaction starts a new transaction.
StartTransaction(ctx context.Context) (Transaction, error)
// CommitTransaction commits the current ongoing transaction.
CommitTransaction() error
// RollbackTransaction rolls back the current ongoing transaction.
RollbackTransaction() error
// InTransaction returns true if the current query compiler is in a transaction.
InTransaction() bool
// BuildSelectQuery builds a select query with the given parameters.
BuildSelectQuery(
ctx context.Context,
qs *QuerySet,
fields []FieldInfo,
where []Expression,
having []Expression,
joins []JoinDef,
groupBy []FieldInfo,
orderBy []OrderBy,
limit int,
offset int,
union []Union,
forUpdate bool,
distinct bool,
) Query[[][]interface{}]
// BuildCountQuery builds a count query with the given parameters.
BuildCountQuery(
ctx context.Context,
qs *QuerySet,
where []Expression,
joins []JoinDef,
groupBy []FieldInfo,
limit int,
offset int,
) CountQuery
// BuildCreateQuery builds a create query with the given parameters.
BuildCreateQuery(
ctx context.Context,
qs *QuerySet,
fields FieldInfo,
primary attrs.Field,
values []any,
) Query[[]interface{}]
// BuildValuesListQuery builds a values list query with the given parameters.
BuildUpdateQuery(
ctx context.Context,
qs *QuerySet,
fields FieldInfo,
where []Expression,
joins []JoinDef,
groupBy []FieldInfo,
values []any,
) CountQuery
// BuildUpdateQuery builds an update query with the given parameters.
BuildDeleteQuery(
ctx context.Context,
qs *QuerySet,
where []Expression,
joins []JoinDef,
groupBy []FieldInfo,
) CountQuery
}
func Compiler ¶ added in v1.0.7
func Compiler(model attrs.Definer) QueryCompiler
func NewGenericQueryBuilder ¶ added in v1.0.7
func NewGenericQueryBuilder(model attrs.Definer) QueryCompiler
type QueryObject ¶ added in v1.0.7
type QueryObject[T1 any] struct { // contains filtered or unexported fields }
func (*QueryObject[T1]) Args ¶ added in v1.0.7
func (q *QueryObject[T1]) Args() []any
func (*QueryObject[T1]) Exec ¶ added in v1.0.7
func (q *QueryObject[T1]) Exec() (T1, error)
func (*QueryObject[T1]) Model ¶ added in v1.0.7
func (q *QueryObject[T1]) Model() attrs.Definer
func (*QueryObject[T1]) SQL ¶ added in v1.0.7
func (q *QueryObject[T1]) SQL() string
type QuerySet ¶
type QuerySet struct {
// contains filtered or unexported fields
}
func (*QuerySet) Compiler ¶ added in v1.0.7
func (qs *QuerySet) Compiler() QueryCompiler
func (*QuerySet) Count ¶
func (qs *QuerySet) Count() CountQuery
func (*QuerySet) Delete ¶ added in v1.0.3
func (qs *QuerySet) Delete() CountQuery
func (*QuerySet) Exists ¶ added in v1.0.3
func (qs *QuerySet) Exists() ExistsQuery
func (*QuerySet) GetOrCreate ¶ added in v1.0.7
func (*QuerySet) Update ¶ added in v1.0.3
func (qs *QuerySet) Update(value attrs.Definer) CountQuery
func (*QuerySet) ValuesList ¶ added in v1.0.3
func (qs *QuerySet) ValuesList(fields ...string) ValuesListQuery
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) Clone ¶ added in v1.0.3
func (e *RawExpr) Clone() Expression
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
type SupportsReturning ¶ added in v1.0.7
type SupportsReturning string
const ( SupportsReturningNone SupportsReturning = "" SupportsReturningLastInsertId SupportsReturning = "last_insert_id" SupportsReturningColumns SupportsReturning = "columns" )
type Transaction ¶ added in v1.0.7
type ValuesListQuery ¶ added in v1.0.3
Click to show internal directories.
Click to hide internal directories.