Documentation
¶
Overview ¶
Package daog,A quickly mysql access component.
Copyright 2023 The daog Authors. All rights reserved.
Package daog,A quickly mysql access component.
Copyright 2023 The daog Authors. All rights reserved.
Package daog,A quickly mysql access component.
Copyright 2023 The daog Authors. All rights reserved.
Package daog,A quickly mysql access component.
Copyright 2023 The daog Authors. All rights reserved.
Package daog,A quickly mysql access component.
Copyright 2023 The daog Authors. All rights reserved.
Package daog,A quickly mysql access component.
Copyright 2023 The daog Authors. All rights reserved.
Package daog,A quickly mysql access component.
Copyright 2023 The daog Authors. All rights reserved.
Package daog,A quickly mysql access component.
Copyright 2023 The daog Authors. All rights reserved.
Package daog,A quickly mysql access component.
Copyright 2023 The daog Authors. All rights reserved.
Index ¶
- Constants
- Variables
- func ConvertToAnySlice[T any](data []T) []any
- func DeleteById[T any](id int64, meta *TableMeta[T], tc *TransContext) (int64, error)
- func DeleteByIds[T any](ids []int64, meta *TableMeta[T], tc *TransContext) (int64, error)
- func DeleteByMatcher[T any](matcher Matcher, meta *TableMeta[T], tc *TransContext) (int64, error)
- func ExecRawSQL(tc *TransContext, sql string, args ...any) (int64, error)
- func GetById[T any](id int64, meta *TableMeta[T], tc *TransContext) (*T, error)
- func GetByIds[T any](ids []int64, meta *TableMeta[T], tc *TransContext) ([]*T, error)
- func GetDatasourceShardingKeyFromCtx(ctx context.Context) any
- func GetTableName[T any](ctx context.Context, meta *TableMeta[T]) string
- func GetTableShardingKeyFromCtx(ctx context.Context) any
- func GetTraceIdFromContext(ctx context.Context) string
- func Insert[T any](ins *T, meta *TableMeta[T], tc *TransContext) (int64, error)
- func QueryListMatcher[T any](m Matcher, meta *TableMeta[T], tc *TransContext) ([]*T, error)
- func QueryOneMatcher[T any](m Matcher, meta *TableMeta[T], tc *TransContext) (*T, error)
- func QueryRawSQL[T any](tc *TransContext, mapper RowFieldPointMapper[T], sql string, args ...any) ([]*T, error)
- func Update[T any](ins *T, meta *TableMeta[T], tc *TransContext) (int64, error)
- func UpdateById[T any](modifier Modifier, id int64, meta *TableMeta[T], tc *TransContext) (int64, error)
- func UpdateByIds[T any](modifier Modifier, ids []int64, meta *TableMeta[T], tc *TransContext) (int64, error)
- func UpdateByModifier[T any](modifier Modifier, matcher Matcher, meta *TableMeta[T], tc *TransContext) (int64, error)
- func UpdateList[T any](insList []*T, meta *TableMeta[T], tc *TransContext) (int64, error)
- type Datasource
- type DatasourceShardingPolicy
- type DbConf
- type LogErrorFunc
- type LogExecSQLAfterFunc
- type LogExecSQLFunc
- type LogInfoFunc
- type Matcher
- type ModInt64ShardingDatasourcePolicy
- type Modifier
- type RowFieldPointMapper
- type SQLCond
- type TableMeta
- type TransContext
Constants ¶
const ( LikeStyleAll = 0 LikeStyleLeft = 1 LikeStyleRight = 2 )
define "and","or" operand define like style, %xx%, %s,s%
const ( TraceId = "trace-id" CtxValues = "values" ShardingKey = "shardingKey" DatasourceShardingKey = "datasourceSharingKey" )
const TableIdColumnName = "id"
Variables ¶
var ( LogError LogErrorFunc LogInfo LogInfoFunc LogExecSQL LogExecSQLFunc LogExecSQLAfter LogExecSQLAfterFunc )
Functions ¶
func ConvertToAnySlice ¶
func DeleteById ¶
func DeleteByIds ¶
func DeleteByMatcher ¶
func ExecRawSQL ¶
func ExecRawSQL(tc *TransContext, sql string, args ...any) (int64, error)
func GetByIds ¶
func GetByIds[T any](ids []int64, meta *TableMeta[T], tc *TransContext) ([]*T, error)
func GetTraceIdFromContext ¶
func QueryListMatcher ¶
func QueryListMatcher[T any](m Matcher, meta *TableMeta[T], tc *TransContext) ([]*T, error)
func QueryOneMatcher ¶
func QueryOneMatcher[T any](m Matcher, meta *TableMeta[T], tc *TransContext) (*T, error)
func QueryRawSQL ¶ added in v0.0.2
func QueryRawSQL[T any](tc *TransContext, mapper RowFieldPointMapper[T], sql string, args ...any) ([]*T, error)
QueryRawSQL 执行原生select sql语句,返回行数据数组,行数据使用T struct描述 mapper, 它T的各个field指针提取出来并按照顺序生成一个slice,用于Row.Scan方法,把sql字段映射到T对象的各个Field上
func UpdateById ¶
func UpdateByIds ¶
func UpdateByModifier ¶
func UpdateList ¶
func UpdateList[T any](insList []*T, meta *TableMeta[T], tc *TransContext) (int64, error)
Types ¶
type Datasource ¶
type Datasource interface {
Shutdown()
IsLogSQL() bool
// contains filtered or unexported methods
}
func NewDatasource ¶
func NewDatasource(conf *DbConf) (Datasource, error)
func NewShardingDatasource ¶
func NewShardingDatasource(confs []*DbConf, policy DatasourceShardingPolicy) (Datasource, error)
type LogErrorFunc ¶
type LogExecSQLAfterFunc ¶
type LogExecSQLFunc ¶
type LogInfoFunc ¶
type Matcher ¶
type Matcher interface {
SQLCond
Add(matcher Matcher) Matcher
AddCond(cond SQLCond) Matcher
Eq(column string, value any) Matcher
Ne(column string, value any) Matcher
Lt(column string, value any) Matcher
Lte(column string, value any) Matcher
Gt(column string, value any) Matcher
Gte(column string, value any) Matcher
In(column string, values []any) Matcher
NotIn(column string, values []any) Matcher
Like(column string, value string, likeStyle int) Matcher
Null(column string, not bool) Matcher
Between(column string, start any, end any) Matcher
}
func NewAndMatcher ¶
func NewAndMatcher() Matcher
func NewMatcher ¶
func NewMatcher() Matcher
func NewOrMatcher ¶
func NewOrMatcher() Matcher
type ModInt64ShardingDatasourcePolicy ¶
type ModInt64ShardingDatasourcePolicy int64
type RowFieldPointMapper ¶ added in v0.0.2
type TableMeta ¶
type TransContext ¶
type TransContext struct {
LogSQL bool
// contains filtered or unexported fields
}
func NewTransContext ¶
func NewTransContext(datasource Datasource, txRequest txrequest.RequestStyle, traceId string) (*TransContext, error)
func NewTransContextWithSharding ¶
func NewTransContextWithSharding(datasource Datasource, txRequest txrequest.RequestStyle, traceId string, shardingKey any, datasourceShardingKey any) (*TransContext, error)
func (*TransContext) Complete ¶
func (tc *TransContext) Complete(e error)