Documentation ¶
Index ¶
- Variables
- func Open(driverName, dataSourceName string) (*sql.DB, error)
- func OpenDB(driver sqldriver.Connector) *sql.DB
- func OpenMysql(dataSourceName string) (*sql.DB, error)
- func Register(name string, drvier sqldriver.Driver)
- func SetErrorLogger(l ErrorLogger)
- func SetInfoLogger(l InfoLogger)
- type ErrorLogger
- type InfoLogger
- type JoinType
- type JsonField
- type JsonInt
- type JsonTime
- type Query
- func (q *Query[T]) Alias(alias string) *Query[T]
- func (q *Query[T]) Clone() *Query[T]
- func (q *Query[T]) CreateStruct(file ...string) error
- func (q *Query[T]) CreateTable() (string, error)
- func (q *Query[T]) DB() *sql.DB
- func (q *Query[T]) DBs() []*sql.DB
- func (q *Query[T]) Delete(primaryIds ...any) QueryResult
- func (q *Query[T]) Execute() QueryResult
- func (q *Query[T]) ForUpdate(forUpdateType ...SelectForUpdateType) *Query[T]
- func (q *Query[T]) Get(primaryIds ...any) (T, QueryResult)
- func (q *Query[T]) GetBool() (bool, QueryResult)
- func (q *Query[T]) GetCount() (int64, QueryResult)
- func (q *Query[T]) GetInt() (int64, QueryResult)
- func (q *Query[T]) GetMapInt() (map[int64]int64, QueryResult)
- func (q *Query[T]) GetMapIntString() (map[int64]string, QueryResult)
- func (q *Query[T]) GetMapSliceString() (map[string][]string, QueryResult)
- func (q *Query[T]) GetMapString() (map[string]string, QueryResult)
- func (q *Query[T]) GetMapStringInt() (map[string]int64, QueryResult)
- func (q *Query[T]) GetMapStringUint() (map[string]uint64, QueryResult)
- func (q *Query[T]) GetMapUint() (map[uint64]uint64, QueryResult)
- func (q *Query[T]) GetMapUintString() (map[uint64]string, QueryResult)
- func (q *Query[T]) GetSliceInt() ([]int64, QueryResult)
- func (q *Query[T]) GetSliceString() ([]string, QueryResult)
- func (q *Query[T]) GetSliceUint() ([]uint64, QueryResult)
- func (q *Query[T]) GetString() (string, QueryResult)
- func (q *Query[T]) GetTo(destPtr any) QueryResult
- func (q *Query[T]) GetUint() (uint64, QueryResult)
- func (q *Query[T]) Gets(primaryIds ...any) ([]T, QueryResult)
- func (q *Query[T]) GroupBy(columns ...any) *Query[T]
- func (q *Query[T]) Having(column any, vals ...any) *Query[T]
- func (q *Query[T]) Insert(data ...T) QueryResult
- func (q *Query[T]) InsertSubquery(data *SubQuery) QueryResult
- func (q *Query[T]) Join(table Table, where func(join *Query[T]) *Query[T], alias ...string) *Query[T]
- func (q *Query[T]) LeftJoin(table Table, where func(join *Query[T]) *Query[T], alias ...string) *Query[T]
- func (q *Query[T]) Limit(limit int) *Query[T]
- func (q *Query[T]) NewDefault() T
- func (q *Query[T]) Offset(offset int) *Query[T]
- func (q *Query[T]) OnConflictUpdate(column any, val any, columnVars ...any) *Query[T]
- func (q *Query[T]) OnConflictUpdates(columnVars map[any]any) *Query[T]
- func (q *Query[T]) OrHaving(column any, vals ...any) *Query[T]
- func (q *Query[T]) OrWhere(column any, vals ...any) *Query[T]
- func (q *Query[T]) OrWhereBetween(column any, valLess, valGreat any) *Query[T]
- func (q *Query[T]) OrWhereFunc(f func(where *Query[T]) *Query[T]) *Query[T]
- func (q *Query[T]) OrWherePrimary(operator any, vals ...any) *Query[T]
- func (q *Query[T]) OrderBy(column any) *Query[T]
- func (q *Query[T]) OrderByDesc(column any) *Query[T]
- func (q *Query[T]) OuterJoin(table Table, where func(join *Query[T]) *Query[T], alias ...string) *Query[T]
- func (q *Query[T]) PartitionBy(column any) *Query[T]
- func (q *Query[T]) Raw(prepareSql string, bindings ...any) *Query[T]
- func (q *Query[T]) RightJoin(table Table, where func(join *Query[T]) *Query[T], alias ...string) *Query[T]
- func (q *Query[T]) Select(columns ...any) *Query[T]
- func (q *Query[T]) SelectAs(column any, as string) *Query[T]
- func (q *Query[T]) SelectExclude(exceptColumns ...any) *Query[T]
- func (q *Query[T]) SelectOver(windowFunc string, f func(query *Query[T]) *Query[T], alias string) *Query[T]
- func (q *Query[T]) SelectOverRaw(windowFunc string, windowName string, alias string) *Query[T]
- func (q *Query[T]) SelectRank(column any, alias string) *Query[T]
- func (q *Query[T]) SelectRankDesc(column any, alias string) *Query[T]
- func (q *Query[T]) SelectRowNumber(column any, alias string) *Query[T]
- func (q *Query[T]) SelectRowNumberDesc(column any, alias string) *Query[T]
- func (q *Query[T]) SelectWithTimeout(duration time.Duration) *Query[T]
- func (q *Query[T]) SubQuery() *SubQuery
- func (q *Query[T]) Transaction(f func(query *Query[T]) error) error
- func (q *Query[T]) Tx() *sql.Tx
- func (q *Query[T]) Union(subquery *SubQuery) *Query[T]
- func (q *Query[T]) UnionAll(subquery *SubQuery) *Query[T]
- func (q *Query[T]) Update(column any, val any, columnVars ...any) QueryResult
- func (q *Query[T]) Updates(columnVars map[any]any) QueryResult
- func (q *Query[T]) UseDB(db ...*sql.DB) *Query[T]
- func (q *Query[T]) UseFirstDB() *Query[T]
- func (q *Query[T]) UseTx(tx *sql.Tx) *Query[T]
- func (q *Query[T]) Where(column any, vals ...any) *Query[T]
- func (q *Query[T]) WhereBetween(column any, valLess, valGreat any) *Query[T]
- func (q *Query[T]) WhereFunc(f func(where *Query[T]) *Query[T]) *Query[T]
- func (q *Query[T]) WherePrimary(operator any, vals ...any) *Query[T]
- func (q *Query[T]) WherePrimaryIfNotZero(val any) *Query[T]
- func (q *Query[T]) WithChildrenOnColumn(pidColumn any) *Query[T]
- func (q *Query[T]) WithContext(ctx context.Context) *Query[T]
- func (q *Query[T]) WithCte(subquery *SubQuery, cteName string, columns ...string) *Query[T]
- func (q *Query[T]) WithParentsOnColumn(pidColumn any) *Query[T]
- func (q *Query[T]) WithRecursiveCte(subquery *SubQuery, cteName string, columns ...string) *Query[T]
- func (q *Query[T]) WithWindow(subquery *SubQuery, windowName string) *Query[T]
- type QueryResult
- type Raw
- type SelectForUpdateType
- type SubQuery
- type Table
- 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("select|where column should be string or ptr of Table.T.field") ErrDestOfGetToMustBePtr = errors.New("dest of Get-to must be ptr") ErrDestOfGetToSliceElemMustNotBePtr = errors.New("dest of Get-to slice elem kind must not be ptr") ErrDestOfGetToMapElemMustNotBePtr = errors.New("dest of Get-to map elem kind must not be ptr") ErrInsertPtrNotAllowed = errors.New("insert ptr data not allowed") ErrUpdateWithoutCondition = errors.New("update without condition not allowed") ErrDeleteWithoutCondition = errors.New("delete without condition not allowed") )
Functions ¶
func SetErrorLogger ¶ added in v0.9.1
func SetErrorLogger(l ErrorLogger)
func SetInfoLogger ¶ added in v0.9.1
func SetInfoLogger(l InfoLogger)
Types ¶
type ErrorLogger ¶ added in v0.9.1
type ErrorLogger interface {
Error(args ...any)
}
type InfoLogger ¶ added in v0.9.1
type InfoLogger interface {
Info(args ...any)
}
type JsonField ¶ added in v0.9.6
type JsonField[T any] struct { Data T }
json ojbect/slice <=> go struct/slice <=> db json string
func NewJsonField ¶ added in v0.9.6
func (JsonField[T]) MarshalJSON ¶ added in v0.9.6
func (*JsonField[T]) UnmarshalJSON ¶ added in v0.9.6
type JsonInt ¶
type JsonInt int64
json int or long string int <=> go int64
func (JsonInt) MarshalJSON ¶
func (*JsonInt) UnmarshalJSON ¶
type JsonTime ¶
json int(13) <=> go time.time
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 (*Query[T]) CreateStruct ¶ added in v0.8.4
func (*Query[T]) CreateTable ¶ added in v0.8.4
func (*Query[T]) Delete ¶
func (q *Query[T]) Delete(primaryIds ...any) QueryResult
func (*Query[T]) ForUpdate ¶ added in v0.4.0
func (q *Query[T]) ForUpdate(forUpdateType ...SelectForUpdateType) *Query[T]
func (*Query[T]) Get ¶ added in v0.3.0
func (q *Query[T]) Get(primaryIds ...any) (T, QueryResult)
get first T
func (*Query[T]) GetBool ¶ added in v0.9.1
func (q *Query[T]) GetBool() (bool, QueryResult)
get first bool
func (*Query[T]) GetCount ¶ added in v0.3.0
func (q *Query[T]) GetCount() (int64, QueryResult)
get count T
func (*Query[T]) GetInt ¶ added in v0.9.1
func (q *Query[T]) GetInt() (int64, QueryResult)
get first int
func (*Query[T]) GetMapInt ¶ added in v1.0.7
func (q *Query[T]) GetMapInt() (map[int64]int64, QueryResult)
func (*Query[T]) GetMapIntString ¶ added in v1.0.7
func (q *Query[T]) GetMapIntString() (map[int64]string, QueryResult)
func (*Query[T]) GetMapSliceString ¶ added in v0.9.5
func (q *Query[T]) GetMapSliceString() (map[string][]string, QueryResult)
func (*Query[T]) GetMapString ¶ added in v0.9.5
func (q *Query[T]) GetMapString() (map[string]string, QueryResult)
func (*Query[T]) GetMapStringInt ¶ added in v1.0.7
func (q *Query[T]) GetMapStringInt() (map[string]int64, QueryResult)
func (*Query[T]) GetMapStringUint ¶ added in v1.0.7
func (q *Query[T]) GetMapStringUint() (map[string]uint64, QueryResult)
func (*Query[T]) GetMapUint ¶ added in v1.0.7
func (q *Query[T]) GetMapUint() (map[uint64]uint64, QueryResult)
func (*Query[T]) GetMapUintString ¶ added in v1.0.7
func (q *Query[T]) GetMapUintString() (map[uint64]string, QueryResult)
func (*Query[T]) GetSliceInt ¶ added in v0.9.5
func (q *Query[T]) GetSliceInt() ([]int64, QueryResult)
↓↓ more Get examples ↓↓
func (*Query[T]) GetSliceString ¶ added in v0.9.5
func (q *Query[T]) GetSliceString() ([]string, QueryResult)
func (*Query[T]) GetSliceUint ¶ added in v0.9.5
func (q *Query[T]) GetSliceUint() ([]uint64, QueryResult)
func (*Query[T]) GetString ¶ added in v0.9.1
func (q *Query[T]) GetString() (string, QueryResult)
get first string
func (*Query[T]) GetTo ¶ added in v0.3.0
func (q *Query[T]) GetTo(destPtr any) QueryResult
destPtr, pointer of any value like: value, []value, map[key]value, map[key][]value
func (*Query[T]) GetUint ¶ added in v0.9.5
func (q *Query[T]) GetUint() (uint64, QueryResult)
func (*Query[T]) Gets ¶ added in v0.3.0
func (q *Query[T]) Gets(primaryIds ...any) ([]T, QueryResult)
get slice T
func (*Query[T]) Insert ¶
func (q *Query[T]) Insert(data ...T) QueryResult
insert and set primary for first T
func (*Query[T]) InsertSubquery ¶ added in v0.3.0
func (q *Query[T]) InsertSubquery(data *SubQuery) QueryResult
func (*Query[T]) NewDefault ¶ added in v1.0.4
func (q *Query[T]) NewDefault() T
func (*Query[T]) OnConflictUpdate ¶ added in v0.9.3
func (*Query[T]) OnConflictUpdates ¶ added in v0.9.3
func (*Query[T]) OrWhereBetween ¶ added in v0.9.1
func (*Query[T]) OrWhereFunc ¶ added in v0.3.0
"id=1" &obj.id, 1 &obj.id, "=", 1
func (*Query[T]) OrWherePrimary ¶ added in v0.7.2
short for OrWhere(primaryKey, vals...)
func (*Query[T]) OrderByDesc ¶
func (*Query[T]) PartitionBy ¶ added in v0.4.0
func (*Query[T]) SelectExclude ¶ added in v0.9.3
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]) SelectRowNumber ¶ added in v0.9.1
func (*Query[T]) SelectRowNumberDesc ¶ added in v0.9.1
func (*Query[T]) SelectWithTimeout ¶ added in v0.7.6
func (*Query[T]) Update ¶
func (q *Query[T]) Update(column any, val any, columnVars ...any) QueryResult
func (*Query[T]) UseFirstDB ¶ added in v1.0.4
func (*Query[T]) WhereBetween ¶ added in v0.9.1
func (*Query[T]) WherePrimary ¶ added in v0.7.2
short for Where(primaryKey, vals...)
func (*Query[T]) WherePrimaryIfNotZero ¶ added in v0.9.3
func (*Query[T]) WithChildrenOnColumn ¶ added in v0.5.1
func (*Query[T]) WithContext ¶ added in v0.7.6
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 []any 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 (SubQuery) Connections ¶ added in v0.8.5
func (SubQuery) DatabaseName ¶ added in v0.3.0
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.go
- create_table.go
- db.go
- err.go
- json_field.go
- json_int.go
- json_time.go
- log.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
- reflect.go
- slice.go
- string.go
- subquery.go
- table.go
- update_column.go
- where.go
Click to show internal directories.
Click to hide internal directories.