Documentation ¶
Index ¶
- func ConnectMysql(config MysqlConfig) (db *gorm.DB, err error)
- func ConnectSqlite(config SqliteConfig) (db *gorm.DB, err error)
- func InOperationUint8(fieldName string, values []uint8, isIn bool) string
- func IsTransaction(db *gorm.DB) error
- func ListByPage(db *gorm.DB, params *ListByPageParams) *gorm.DB
- func Transaction[T any](db *gorm.DB, f TransactionFunc[T]) (data T, err error)
- type ConditionItem
- type ListByPageParams
- type MysqlConfig
- type SqliteConfig
- type TransactionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InOperationUint8 ¶
由于xxx in/not in (?)时,如果值数组是uint8数组,则GORM会按照字符串处理
func Transaction ¶
func Transaction[T any](db *gorm.DB, f TransactionFunc[T]) (data T, err error)
GORM事务处理
Types ¶
type ListByPageParams ¶
type ListByPageParams struct { PageNumber uint64 `json:"page_number"` // 从1开始的页码 PageSize uint64 `json:"page_size"` // 大于1为有效的页大小 Sort map[string]string `json:"sort"` // 排序信息(仅支持一个),[字段名:ascend/descend] }
分页查询列表的公共参数
type MysqlConfig ¶
type MysqlConfig struct { Host string // 服务器主机地址 Port int // 服务器端口号 User string // 服务器登陆用户 Password string // 调试时数据库密码 Scheme string // 数据库名称 MaxIdleConnection int // 最大闲置连接数 MaxOpenConnection int // 最大打开连接数 DebugMode bool // 开启SQL调试模式 Params map[string]string // 连接参数 }
MySQL的配置信息
type SqliteConfig ¶
type SqliteConfig struct { Filepath string // 文件地址 Password string // 调试时数据库密码 DebugMode bool // 开启SQL调试模式 }
SQLite的配置信息
Click to show internal directories.
Click to hide internal directories.