Documentation ¶
Index ¶
- Variables
- func Auth[T contracts.Authenticatable](f InstanceFactory[T], table, primaryKey string) contracts.QueryBuilder[T]
- func SetFactory(dbFactory contracts.DBFactory)
- func WithTX[T any](name string, tx contracts.DBTx) contracts.QueryBuilder[T]
- type CreateException
- type DeleteException
- type Exception
- type InsertException
- type InstanceFactory
- type NotFoundException
- type SelectException
- type Table
- func (table *Table[T]) Avg(column string) float64
- func (table *Table[T]) AvgE(column string) (float64, contracts.Exception)
- func (table *Table[T]) Chunk(size int, ...) (err contracts.Exception)
- func (table *Table[T]) ChunkById(size int, ...) contracts.Exception
- func (table *Table[T]) ChunkByIdDesc(size int, ...) contracts.Exception
- func (table *Table[T]) Count(columns ...string) int64
- func (table *Table[T]) CountE(columns ...string) (int64, contracts.Exception)
- func (table *Table[T]) Create(fields contracts.Fields) *T
- func (table *Table[T]) CreateE(fields contracts.Fields) (*T, contracts.Exception)
- func (table *Table[T]) Delete() int64
- func (table *Table[T]) DeleteE() (int64, contracts.Exception)
- func (table *Table[T]) Find(key any) *T
- func (table *Table[T]) FindOrFail(key any) *T
- func (table *Table[T]) First() *T
- func (table *Table[T]) FirstE() (*T, contracts.Exception)
- func (table *Table[T]) FirstOr(provider contracts.InstanceProvider[*T]) *T
- func (table *Table[T]) FirstOrCreate(where contracts.Fields, values ...contracts.Fields) *T
- func (table *Table[T]) FirstOrCreateE(where contracts.Fields, values ...contracts.Fields) (*T, contracts.Exception)
- func (table *Table[T]) FirstOrFail() *T
- func (table *Table[T]) FirstWhere(column string, args ...any) *T
- func (table *Table[T]) FirstWhereE(column string, args ...any) (*T, contracts.Exception)
- func (table *Table[T]) Get() contracts.Collection[*T]
- func (table *Table[T]) GetE() (contracts.Collection[*T], contracts.Exception)
- func (table *Table[T]) GetPrimaryKeyField() string
- func (table *Table[T]) GetTable() string
- func (table *Table[T]) Insert(values ...contracts.Fields) bool
- func (table *Table[T]) InsertE(values ...contracts.Fields) contracts.Exception
- func (table *Table[T]) InsertGetId(values ...contracts.Fields) int64
- func (table *Table[T]) InsertGetIdE(values ...contracts.Fields) (int64, contracts.Exception)
- func (table *Table[T]) InsertOrIgnore(values ...contracts.Fields) int64
- func (table *Table[T]) InsertOrIgnoreE(values ...contracts.Fields) (int64, contracts.Exception)
- func (table *Table[T]) InsertOrReplace(values ...contracts.Fields) int64
- func (table *Table[T]) InsertOrReplaceE(values ...contracts.Fields) (int64, contracts.Exception)
- func (table *Table[T]) Max(column string) float64
- func (table *Table[T]) MaxE(column string) (float64, contracts.Exception)
- func (table *Table[T]) Min(column string) float64
- func (table *Table[T]) MinE(column string) (float64, contracts.Exception)
- func (table *Table[T]) Paginate(perPage int64, current ...int64) (contracts.Collection[*T], int64)
- func (table *Table[T]) SelectForUpdate() contracts.Collection[*T]
- func (table *Table[T]) SelectForUpdateE() (contracts.Collection[*T], contracts.Exception)
- func (table *Table[T]) SetByRelation(relation contracts.Relation[any, T]) *Table[T]
- func (table *Table[T]) SetConnection(connection any) *Table[T]
- func (table *Table[T]) SetCreatedTimeColumn(column string) *Table[T]
- func (table *Table[T]) SetExecutor(executor contracts.SqlExecutor) *Table[T]
- func (table *Table[T]) SetFactory(factory InstanceFactory[T]) *Table[T]
- func (table *Table[T]) SetPrimaryKey(name string) *Table[T]
- func (table *Table[T]) SetRelation(relation contracts.RelationType, collector contracts.ForeignKeysCollector[T], ...) *Table[T]
- func (table *Table[T]) SetUpdatedTimeColumn(column string) *Table[T]
- func (table *Table[T]) SetWiths(withs ...contracts.RelationType) *Table[T]
- func (table *Table[T]) SimplePaginate(perPage int64, current ...int64) contracts.Collection[*T]
- func (table *Table[T]) Sum(column string) float64
- func (table *Table[T]) SumE(column string) (float64, contracts.Exception)
- func (table *Table[T]) Update(fields contracts.Fields) int64
- func (table *Table[T]) UpdateE(fields contracts.Fields) (int64, contracts.Exception)
- func (table *Table[T]) UpdateOrCreate(attributes contracts.Fields, values contracts.Fields) *T
- func (table *Table[T]) UpdateOrCreateE(attributes contracts.Fields, values contracts.Fields) (*T, contracts.Exception)
- func (table *Table[T]) UpdateOrInsert(attributes contracts.Fields, values contracts.Fields) bool
- func (table *Table[T]) UpdateOrInsertE(attributes contracts.Fields, values contracts.Fields) contracts.Exception
- type UpdateException
Constants ¶
This section is empty.
Variables ¶
var InsertError = errors.New("insert statement execution failed")
var UpdateErr = errors.New("update statement execution failed")
Functions ¶
func Auth ¶ added in v0.2.0
func Auth[T contracts.Authenticatable](f InstanceFactory[T], table, primaryKey string) contracts.QueryBuilder[T]
func SetFactory ¶ added in v0.1.15
Types ¶
type CreateException ¶
type CreateException = Exception
type DeleteException ¶
type DeleteException = Exception
type Exception ¶ added in v0.1.14
type Exception struct { Sql string Bindings []any Err error // contains filtered or unexported fields }
func (*Exception) GetPrevious ¶ added in v0.1.14
type InsertException ¶
type InsertException = Exception
type InstanceFactory ¶ added in v0.4.4
type NotFoundException ¶
type NotFoundException = Exception
type SelectException ¶
type SelectException = Exception
type Table ¶
type Table[T any] struct { *querybuilder.Builder[T] UpdatedTimeColumn string // contains filtered or unexported fields }
func NewQuery ¶ added in v0.4.4
func NewQuery[T any](name string, factory InstanceFactory[T]) *Table[T]
NewQuery 将使用默认 connection
func WithConnection ¶
WithConnection 使用指定链接
func (*Table[T]) ChunkByIdDesc ¶ added in v0.2.0
func (table *Table[T]) ChunkByIdDesc(size int, handler func(collection contracts.Collection[*T], page int) (any, contracts.Exception)) contracts.Exception
ChunkByIdDesc 通过比较 ID 对查询结果进行分块 chunk the results of a query by comparing IDs.
func (*Table[T]) FindOrFail ¶ added in v0.2.0
FindOrFail 按 ID 对单个记录执行查询 Execute a query for a single record by ID.
func (*Table[T]) FirstOr ¶ added in v0.2.0
func (table *Table[T]) FirstOr(provider contracts.InstanceProvider[*T]) *T
FirstOr 执行查询并获得第一个结果或调用回调 Execute the query and get the first result or call a callback.
func (*Table[T]) FirstOrCreate ¶
func (*Table[T]) FirstOrCreateE ¶ added in v0.2.0
func (*Table[T]) FirstOrFail ¶
func (table *Table[T]) FirstOrFail() *T
func (*Table[T]) FirstWhere ¶ added in v0.2.0
FirstWhere 向查询添加基本 where 子句,并返回第一个结果 Add a basic where clause to the query, and return the first result.
func (*Table[T]) FirstWhereE ¶ added in v0.2.0
FirstWhereE 向查询添加基本 where 子句,并返回第一个结果 Add a basic where clause to the query, and return the first result.
func (*Table[T]) Get ¶
func (table *Table[T]) Get() contracts.Collection[*T]
func (*Table[T]) GetE ¶ added in v0.2.0
func (table *Table[T]) GetE() (contracts.Collection[*T], contracts.Exception)
func (*Table[T]) GetPrimaryKeyField ¶ added in v0.4.4
func (*Table[T]) InsertGetIdE ¶ added in v0.2.0
func (*Table[T]) InsertOrIgnore ¶
func (*Table[T]) InsertOrIgnoreE ¶ added in v0.2.0
func (*Table[T]) InsertOrReplace ¶
InsertOrReplace 将新记录插入数据库,同时如果存在,则先删除此行数据,然后插入新的数据 Insert a new record into the database, and if it exists, delete this row of data first, and then insert new data.
func (*Table[T]) InsertOrReplaceE ¶ added in v0.2.0
func (*Table[T]) SelectForUpdate ¶ added in v0.1.5
func (table *Table[T]) SelectForUpdate() contracts.Collection[*T]
func (*Table[T]) SelectForUpdateE ¶ added in v0.2.0
func (table *Table[T]) SelectForUpdateE() (contracts.Collection[*T], contracts.Exception)
func (*Table[T]) SetByRelation ¶ added in v0.5.2
SetByRelation 设置关联关系
func (*Table[T]) SetConnection ¶
SetConnection 参数要么是 contracts.DBConnection 要么是 string
func (*Table[T]) SetCreatedTimeColumn ¶ added in v0.2.6
SetCreatedTimeColumn 设置创建时间字段
func (*Table[T]) SetExecutor ¶
func (table *Table[T]) SetExecutor(executor contracts.SqlExecutor) *Table[T]
SetExecutor 参数必须是 contracts.DBTx 实例
func (*Table[T]) SetFactory ¶ added in v0.4.4
func (table *Table[T]) SetFactory(factory InstanceFactory[T]) *Table[T]
SetFactory 设置类
func (*Table[T]) SetPrimaryKey ¶
SetPrimaryKey 设置主键
func (*Table[T]) SetRelation ¶ added in v0.5.2
func (table *Table[T]) SetRelation( relation contracts.RelationType, collector contracts.ForeignKeysCollector[T], relationCollector contracts.RelationCollector, setter contracts.RelationSetter[T], ) *Table[T]
SetRelation 设置关联关系
func (*Table[T]) SetUpdatedTimeColumn ¶ added in v0.2.6
SetUpdatedTimeColumn 设置更新时间字段
func (*Table[T]) SetWiths ¶ added in v0.5.2
func (table *Table[T]) SetWiths(withs ...contracts.RelationType) *Table[T]
SetWiths 初始化关联查询
func (*Table[T]) SimplePaginate ¶ added in v0.2.0
func (table *Table[T]) SimplePaginate(perPage int64, current ...int64) contracts.Collection[*T]
SimplePaginate 将给定的查询分页成一个简单的分页器 paginate the given query into a simple paginator.
func (*Table[T]) UpdateOrCreate ¶
func (*Table[T]) UpdateOrCreateE ¶ added in v0.2.0
func (*Table[T]) UpdateOrInsert ¶
type UpdateException ¶
type UpdateException = Exception