Documentation ¶
Index ¶
- func ConvertLevel(level string) log.LogLevel
- func FindOne(db *gorm.DB, out interface{}) (bool, error)
- func FindPage(ctx context.Context, db *gorm.DB, pp PaginationParam, out interface{}) (int64, error)
- func FromNoTrans(ctx context.Context) bool
- func FromTraceID(ctx context.Context) (string, bool)
- func FromTrans(ctx context.Context) (interface{}, bool)
- func FromTransLock(ctx context.Context) bool
- func FromUserID(ctx context.Context) uint64
- func FromUserName(ctx context.Context) string
- func GetDB(ctx context.Context, defDB *gorm.DB) *gorm.DB
- func GetDbWithModel(ctx context.Context, defDB *gorm.DB, m interface{}) *gorm.DB
- func NewNoTrans(ctx context.Context) context.Context
- func NewTraceID(ctx context.Context, traceID string) context.Context
- func NewTrans(ctx context.Context, trans interface{}) context.Context
- func NewTransLock(ctx context.Context) context.Context
- func NewUserID(ctx context.Context, userID uint64) context.Context
- func NewUserName(ctx context.Context, userName string) context.Context
- func ParseOrder(items []*OrderField, handle ...OrderFieldFunc) string
- func Register(name string, driverFunc DriverFunc)
- type Config
- type DB
- type Dialector
- type DriverFunc
- type GormConfig
- type LogConfig
- type Model
- type OrderDirection
- type OrderField
- type OrderFieldFunc
- type PaginationParam
- type PaginationResult
- type QueryOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDbWithModel ¶
GetDbWithModel 获取db
func NewTraceID ¶
NewTraceID 创建追踪ID的上下文
func NewUserName ¶
NewUserName 创建用户名的上下文
func ParseOrder ¶
func ParseOrder(items []*OrderField, handle ...OrderFieldFunc) string
ParseOrder 解析排序字段
Types ¶
type Config ¶
type Config struct { Drive string `json:"drive"` // 驱动 DNS string `json:"dns"` // 连接字符串 Debug bool `json:"debug"` // 是否开启调试 MaxIdleConns int `json:"max_idle_conns"` // 最大空闲连接数 MaxOpenConns int `json:"max_open_conns"` // 最大活动连接数 ConnMaxLifetime time.Duration `json:"conn_max_lifetime"` // 连接的最大存活时间 *GormConfig // gorm初始化配置 *LogConfig // 日志配置 // contains filtered or unexported fields }
Config 配置信息
func (*Config) WithDialector ¶
WithDialector 单独设置Dialector
type DriverFunc ¶
type GormConfig ¶
type LogConfig ¶
type LogConfig struct { SlowThreshold time.Duration // 日志时间阈值 Colorful bool // 是否开启日志颜色区别 LogLevel string // 日志等级 }
LogConfig 日志配置
type OrderDirection ¶
type OrderDirection int
OrderDirection 排序方向
const ( // OrderByASC 升序排序 OrderByASC OrderDirection = iota + 1 // OrderByDESC 降序排序 OrderByDESC )
type OrderField ¶
type OrderField struct { Key string // 字段名(字段名约束为小写蛇形) Direction OrderDirection // 排序方向 }
OrderField 排序字段
func NewOrderField ¶
func NewOrderField(key string, d OrderDirection) *OrderField
NewOrderField 创建排序字段
type PaginationParam ¶
type PaginationParam struct { Pagination bool `form:"-"` // 是否使用分页查询 OnlyCount bool `form:"-"` // 是否仅查询count Page int `form:"page,default=1"` // 当前页 PageSize int `form:"pageSize,default=10" binding:"max=100"` // 页大小 }
PaginationParam 分页查询参数
type PaginationResult ¶
type PaginationResult struct { Total int64 `json:"total"` Page int `json:"page"` PageSize int `json:"page_size"` }
PaginationResult 分页查询结果
func WrapPageQuery ¶
func WrapPageQuery(ctx context.Context, db *gorm.DB, pp PaginationParam, out interface{}) (*PaginationResult, error)
WrapPageQuery 包装带有分页的查询
type QueryOptions ¶
type QueryOptions struct { OrderFields []*OrderField // 排序字段 SelectFields []string // 查询字段 }
QueryOptions 查询可选参数项
Source Files ¶
Click to show internal directories.
Click to hide internal directories.