Documentation
¶
Index ¶
- Variables
- func Auth(class contracts.Class[contracts.Authenticatable], table, primaryKey string) contracts.Query[contracts.Authenticatable]
- func SetFactory(dbFactory contracts.DBFactory)
- func WithTX[T any](name string, tx contracts.DBTx) contracts.Query[T]
- type BaseModel
- type CreateException
- type DeleteException
- type Exception
- type InsertException
- type NotFoundException
- type SelectException
- type Table
- func ArrayQuery(name string) *Table[contracts.Fields]
- func Class[T any](class contracts.Class[T], table string) *Table[T]
- func FromModel[T any](model contracts.Model[T]) *Table[T]
- func Model[T any](class contracts.Class[T], table string, connection ...string) *Table[T]
- func Query[T any](name string) *Table[T]
- func WithConnection[T any](name string, connection any) *Table[T]
- 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]) 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]) SetClass(class contracts.Class[T]) *Table[T]
- func (table *Table[T]) SetConnection(connection any) *Table[T]
- func (table *Table[T]) SetExecutor(executor contracts.SqlExecutor) contracts.Query[T]
- func (table *Table[T]) SetPrimaryKey(name string) *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(class contracts.Class[contracts.Authenticatable], table, primaryKey string) contracts.Query[contracts.Authenticatable]
func SetFactory ¶ added in v0.1.15
Types ¶
type BaseModel ¶ added in v0.1.3
type BaseModel[T any] struct { // contains filtered or unexported fields }
func (BaseModel[T]) GetConnection ¶ added in v0.1.3
func (BaseModel[T]) GetPrimaryKey ¶ added in v0.1.3
func (BaseModel[T]) SetPrimaryKey ¶ added in v0.1.3
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 NotFoundException ¶
type NotFoundException = Exception
type SelectException ¶
type SelectException = Exception
type Table ¶
type Table[T any] struct { contracts.QueryBuilder[T] // contains filtered or unexported fields }
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]) 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]) SetConnection ¶
SetConnection 参数要么是 contracts.DBConnection 要么是 string
func (*Table[T]) SetExecutor ¶
func (table *Table[T]) SetExecutor(executor contracts.SqlExecutor) contracts.Query[T]
SetExecutor 参数必须是 contracts.DBTx 实例
func (*Table[T]) SetPrimaryKey ¶
SetPrimaryKey 设置主键
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