Documentation ¶
Index ¶
- Variables
- func Check(ctx context.Context, db *gorm.DB) (bool, error)
- func ExecTrans(ctx context.Context, db *gorm.DB, fn TransFunc) error
- func ExecTransWithLock(ctx context.Context, db *gorm.DB, fn TransFunc) error
- func FindOne(ctx context.Context, db *gorm.DB, out interface{}) (bool, error)
- func FindPage(ctx context.Context, db *gorm.DB, pp PaginationParam, out interface{}) (int, error)
- func GetDB(ctx context.Context, defDB *gorm.DB) *gorm.DB
- func GetDBWithModel(ctx context.Context, defDB *gorm.DB, m interface{}) *gorm.DB
- func NewDB(c *Config) (*gorm.DB, error)
- func NewMongoClient(cfg *MongoConfig) (*mongo.Client, error)
- func ParseOrder(items []*OrderField, handle ...OrderFieldFunc) string
- func ToString(v interface{}) string
- type Config
- type ListResult
- type Model
- type MongoConfig
- type OrderDirection
- type OrderField
- type OrderFieldFunc
- type PaginationParam
- type PaginationResult
- type RecordIDResult
- type Trans
- type TransFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var ( PrefixTable = "" IsSelectForUpdate = true )
Functions ¶
func ExecTransWithLock ¶
ExecTransWithLock 执行事务(加锁)
func GetDBWithModel ¶
func NewMongoClient ¶
func NewMongoClient(cfg *MongoConfig) (*mongo.Client, error)
NewClient 创建mongo客户端实例
func ParseOrder ¶
func ParseOrder(items []*OrderField, handle ...OrderFieldFunc) string
ParseOrder 解析排序字段
Types ¶
type Config ¶
type Config struct { Debug bool `json:"debug"` DBType string `json:"db_type"` DSN string `json:"dsn"` MaxLifetime int `json:"max_lifetime"` MaxOpenConns int `json:"max_open_conns"` MaxIdleConns int `json:"max_idle_conns"` }
Config 配置参数
type ListResult ¶
type ListResult struct { List interface{} `json:"list"` Pagination *PaginationResult `json:"pagination,omitempty"` }
ListResult 响应列表数据
type Model ¶
type Model struct { ID uint `gorm:"column:id;primary_key;auto_increment;"` RecordID string `gorm:"column:record_id;size:36;index;default:'';not null;"` CreatedAt time.Time `gorm:"column:created_at;index;"` UpdatedAt time.Time `gorm:"column:updated_at;index;"` DeletedAt *time.Time `gorm:"column:deleted_at;index;"` }
Model base model
type MongoConfig ¶
Config 配置参数
type OrderDirection ¶
type OrderDirection int
OrderDirection 排序方向
const ( // OrderByASC 升序排序 OrderByASC OrderDirection = 1 // OrderByDESC 降序排序 OrderByDESC OrderDirection = 2 )
type OrderField ¶
type OrderField struct { Key string // 字段名(字段名约束为小写蛇形) Direction OrderDirection // 排序方向 }
OrderField 排序字段
func NewOrderField ¶
func NewOrderField(key string, d OrderDirection) *OrderField
NewOrderField 创建排序字段
func NewOrderFields ¶
func NewOrderFields(keys []string, directions ...map[int]OrderDirection) []*OrderField
NewOrderFields 创建排序字段(默认升序排序),可指定不同key的排序规则 keys 需要排序的key directions 排序规则,按照key的索引指定,索引默认从0开始
type PaginationParam ¶
type PaginationParam struct { Pagination bool `form:"-"` // 是否使用分页查询 OnlyCount bool `form:"-"` // 是否仅查询count Current uint `form:"current"` // 当前页 PageSize uint `form:"pageSize"` // 页大小 }
PaginationParam 分页查询条件
type PaginationResult ¶
type PaginationResult struct { Total int `json:"total"` Current uint `json:"current"` PageSize uint `json:"pageSize"` }
PaginationResult 分页查询结果
func WrapPageQuery ¶
func WrapPageQuery(ctx context.Context, db *gorm.DB, pp PaginationParam, out interface{}) (*PaginationResult, error)
WrapPageQuery 包装带有分页的查询
type RecordIDResult ¶
type RecordIDResult struct {
RecordID string `json:"record_id"`
}
RecordIDResult 响应记录ID
func NewRecordIDResult ¶
func NewRecordIDResult(recordID string) *RecordIDResult
NewRecordIDResult 创建响应记录ID实例
Click to show internal directories.
Click to hide internal directories.