Documentation
¶
Index ¶
- Variables
- func CreateStructFromTable[T Table](queryTable Query[T]) error
- func CreateTableFromStruct[T Table](query Query[T]) (string, error)
- func FillDefaults(table Table)
- func SliceContain(array interface{}, val interface{}) (index int)
- type JoinType
- type JsonInt
- type JsonTime
- type Query
- func (m Query[T]) Alias(alias string) Query[T]
- func (m Query[T]) AllCols() string
- func (m Query[T]) DB() *sql.DB
- func (m Query[T]) Delete(primaryIds ...interface{}) QueryResult
- func (m Query[T]) Execute() QueryResult
- func (m Query[T]) ForUpdate(forUpdateType ...SelectForUpdateType) Query[T]
- func (m Query[T]) FromTable(table Table, alias ...string) Query[T]
- func (m Query[T]) Get(primaryValue ...interface{}) (T, QueryResult)
- func (m Query[T]) GetCount() (int64, QueryResult)
- func (m Query[T]) GetRow() (map[string]interface{}, QueryResult)
- func (m Query[T]) GetRows() ([]map[string]interface{}, QueryResult)
- func (m Query[T]) GetTo(destPtr interface{}) QueryResult
- func (m Query[T]) Gets(primaryIds ...interface{}) ([]T, QueryResult)
- func (m Query[T]) GroupBy(columns ...interface{}) Query[T]
- func (m Query[T]) Having(column interface{}, vals ...interface{}) Query[T]
- func (m Query[T]) Insert(data T, tableFieldPtrs ...interface{}) QueryResult
- func (m Query[T]) InsertSubquery(data SubQuery, tableFieldPtrs []interface{}, updates ...UpdateColumn) QueryResult
- func (m Query[T]) Inserts(data []T, tableFieldPtrs ...interface{}) QueryResult
- func (m Query[T]) InsertsIgnore(data []T, tableFieldPtrs []interface{}, updates ...UpdateColumn) QueryResult
- func (m Query[T]) Join(table Table, where func(join Query[T]) Query[T], alias ...string) Query[T]
- func (m Query[T]) LeftJoin(table Table, where func(join Query[T]) Query[T], alias ...string) Query[T]
- func (m Query[T]) Limit(limit int) Query[T]
- func (m Query[T]) Offset(offset int) Query[T]
- func (m Query[T]) OrWhere(column interface{}, vals ...interface{}) Query[T]
- func (m Query[T]) OrWhereFunc(f func(Query[T]) Query[T]) Query[T]
- func (m Query[T]) OrderBy(column interface{}) Query[T]
- func (m Query[T]) OrderByDesc(column interface{}) Query[T]
- func (m Query[T]) OuterJoin(table Table, where func(join Query[T]) Query[T], alias ...string) Query[T]
- func (m Query[T]) PartitionBy(column interface{}) Query[T]
- func (m Query[T]) Raw(prepareSql string, bindings ...interface{}) Query[T]
- func (m Query[T]) RightJoin(table Table, where func(join Query[T]) Query[T], alias ...string) Query[T]
- func (m Query[T]) Select(columns ...interface{}) Query[T]
- func (m Query[T]) SelectOver(windowFunc string, f func(query Query[T]) Query[T], alias string) Query[T]
- func (m Query[T]) SelectOverRaw(windowFunc string, windowName string, alias string) Query[T]
- func (m Query[T]) SelectRank(column interface{}, alias string) Query[T]
- func (m Query[T]) SelectRankDesc(column interface{}, alias string) Query[T]
- func (m Query[T]) SubQuery() SubQuery
- func (m Query[T]) TableInterface() Table
- func (m Query[T]) Transaction(q func(tx *sql.Tx) error) error
- func (m Query[T]) Union(subquery SubQuery) Query[T]
- func (m Query[T]) UnionAll(subquery SubQuery) Query[T]
- func (m Query[T]) Update(column interface{}, val interface{}) QueryResult
- func (m Query[T]) Updates(updates ...UpdateColumn) QueryResult
- func (m Query[T]) UseDB(db *sql.DB) Query[T]
- func (m Query[T]) UseTx(tx *sql.Tx) Query[T]
- func (m Query[T]) Where(column interface{}, vals ...interface{}) Query[T]
- func (m Query[T]) WhereFunc(f func(Query[T]) Query[T]) Query[T]
- func (m Query[T]) WithChildrenOnColumn(selfPidColumn interface{}) Query[T]
- func (m Query[T]) WithCte(subquery SubQuery, cteName string, columns ...string) Query[T]
- func (m Query[T]) WithParentsOnColumn(childPidColumn interface{}) Query[T]
- func (m Query[T]) WithRecursiveCte(subquery SubQuery, cteName string, columns ...string) Query[T]
- func (m Query[T]) WithWindow(subquery SubQuery, windowName string) Query[T]
- type QueryResult
- type Raw
- type SelectForUpdateType
- type SubQuery
- type Table
- type UpdateColumn
- type WhereOperator
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrDbNotSelected = errors.New("db not selecteed") ErrTableNotExisted = errors.New("table not existed") ErrTableNotSelected = errors.New("table not selected") ErrColumnNotSelected = errors.New("column not selected") ErrColumnNotExisted = errors.New("column not existed") ErrRawSqlRequired = errors.New("raw sql required") ErrParamMustBePtr = errors.New("param must be ptr") ErrParamElemKindMustBeStruct = errors.New("param elem kind must be struct") ErrColumnShouldBeStringOrPtr = errors.New("column should be string or ptr") ErrDestOfGetToMustBePtr = errors.New("dest of Get-to must be ptr") ErrDestOfGetToSliceElemMustNotBePtr = errors.New("dest of Get-to slice elem kind must not be ptr") ErrDestOfGetToSliceElemMustBeStruct = errors.New("dest of Get-to slice elem kind must be struct") )
Functions ¶
func CreateStructFromTable ¶ added in v0.2.0
func CreateTableFromStruct ¶ added in v0.2.0
func FillDefaults ¶ added in v0.4.0
func FillDefaults(table Table)
func SliceContain ¶
func SliceContain(array interface{}, val interface{}) (index int)
Types ¶
type JsonTime ¶
func (JsonTime) MarshalJSON ¶
MarshalJSON on JsonTime format Time field with %Y-%m-%d %H:%M:%S
func (*JsonTime) UnmarshalJSON ¶
MarshalJSON on JsonTime format Time field with %Y-%m-%d %H:%M:%S
type Query ¶
type Query[T Table] struct { T *T // contains filtered or unexported fields }
func NewQueryRaw ¶ added in v0.5.1
func NewQuerySub ¶ added in v0.5.3
func (Query[T]) Delete ¶
func (m Query[T]) Delete(primaryIds ...interface{}) QueryResult
func (Query[T]) ForUpdate ¶ added in v0.4.0
func (m Query[T]) ForUpdate(forUpdateType ...SelectForUpdateType) Query[T]
func (Query[T]) Get ¶ added in v0.3.0
func (m Query[T]) Get(primaryValue ...interface{}) (T, QueryResult)
get first T
func (Query[T]) GetCount ¶ added in v0.3.0
func (m Query[T]) GetCount() (int64, QueryResult)
get count T
func (Query[T]) GetRow ¶ added in v0.3.0
func (m Query[T]) GetRow() (map[string]interface{}, QueryResult)
get first row
func (Query[T]) GetRows ¶ added in v0.3.0
func (m Query[T]) GetRows() ([]map[string]interface{}, QueryResult)
get slice row
func (Query[T]) GetTo ¶ added in v0.3.0
func (m Query[T]) GetTo(destPtr interface{}) QueryResult
destPtr: *int | *int64 | *string | ... destPtr: *[]int | *[]string | ... destPtr: *struct | *[]struct destPtr: *map [int | string | ...] int | string ... destPtr: *map [int | string | ...] struct destPtr: *map [int | string | ...] []struct
func (Query[T]) Gets ¶ added in v0.3.0
func (m Query[T]) Gets(primaryIds ...interface{}) ([]T, QueryResult)
get slice T
func (Query[T]) Insert ¶
func (m Query[T]) Insert(data T, tableFieldPtrs ...interface{}) QueryResult
tableFieldPtrs: allow insert table columns
func (Query[T]) InsertSubquery ¶ added in v0.3.0
func (m Query[T]) InsertSubquery(data SubQuery, tableFieldPtrs []interface{}, updates ...UpdateColumn) QueryResult
func (Query[T]) Inserts ¶ added in v0.3.0
func (m Query[T]) Inserts(data []T, tableFieldPtrs ...interface{}) QueryResult
tableFieldPtrs: allow insert table columns
func (Query[T]) InsertsIgnore ¶ added in v0.3.0
func (m Query[T]) InsertsIgnore(data []T, tableFieldPtrs []interface{}, updates ...UpdateColumn) QueryResult
insert ignore ... // on duplicate key update ...
func (Query[T]) OrWhereFunc ¶ added in v0.3.0
"id=1" &obj.id, 1 &obj.id, "=", 1
func (Query[T]) OrderByDesc ¶
func (Query[T]) PartitionBy ¶ added in v0.4.0
func (Query[T]) SelectOver ¶ added in v0.5.2
func (Query[T]) SelectOverRaw ¶ added in v0.5.3
func (Query[T]) SelectRank ¶ added in v0.4.0
func (Query[T]) SelectRankDesc ¶ added in v0.5.2
func (Query[T]) TableInterface ¶ added in v0.3.0
func (Query[T]) Update ¶
func (m Query[T]) Update(column interface{}, val interface{}) QueryResult
func (Query[T]) Updates ¶
func (m Query[T]) Updates(updates ...UpdateColumn) QueryResult
func (Query[T]) WithChildrenOnColumn ¶ added in v0.5.1
func (Query[T]) WithParentsOnColumn ¶ added in v0.5.1
func (Query[T]) WithRecursiveCte ¶ added in v0.5.1
type QueryResult ¶
type QueryResult struct {
PrepareSql string
Bindings []interface{}
LastInsertId int64
RowsAffected int64
Err error
}
func (QueryResult) Error ¶ added in v0.3.0
func (q QueryResult) Error() error
func (QueryResult) Sql ¶
func (q QueryResult) Sql() string
type SelectForUpdateType ¶ added in v0.4.0
type SelectForUpdateType string
const ( SelectForUpdateTypeDefault SelectForUpdateType = "for update" SelectForUpdateTypeNowait SelectForUpdateType = "for update nowait" SelectForUpdateTypeSkipLocked SelectForUpdateType = "for update skip locked" )
type SubQuery ¶ added in v0.3.0
type SubQuery struct {
// contains filtered or unexported fields
}
func NewSubQuery ¶ added in v0.5.1
func (SubQuery) DatabaseName ¶ added in v0.3.0
type UpdateColumn ¶
type UpdateColumn struct {
Column interface{}
Val interface{}
}
type WhereOperator ¶
type WhereOperator Raw
const ( WhereEqual WhereOperator = "=" WhereNotEqual WhereOperator = "!=" WhereGreatThan WhereOperator = ">" WhereGreaterOrEqual WhereOperator = ">=" WhereLessThan WhereOperator = "<" WhereLessOrEqual WhereOperator = "<=" WhereIn WhereOperator = "in" WhereNotIn WhereOperator = "not in" WhereLike WhereOperator = "like" WhereNotLike WhereOperator = "not like" WhereRlike WhereOperator = "rlike" WhereNotRlike WhereOperator = "not rlike" WhereIsNull WhereOperator = "is null" WhereIsNotNull WhereOperator = "is not null" )
Source Files
¶
- create_struct_from_table.go
- create_table_from_struct.go
- err.go
- fill_default.go
- json_fields.go
- json_int.go
- json_slice.go
- json_time.go
- query.go
- query_delete.go
- query_execute.go
- query_get.go
- query_insert.go
- query_join.go
- query_raw.go
- query_result.go
- query_select.go
- query_select_gen.go
- query_table.go
- query_table_cache.go
- query_transaction.go
- query_union.go
- query_update.go
- query_where.go
- query_window.go
- query_with.go
- string.go
- subquery.go
- table.go
- update_column.go
- where.go
Click to show internal directories.
Click to hide internal directories.