Documentation
¶
Overview ¶
Package sqlite 提供 SQLite 数据库的 ORM 封装,基于 GORM,包含连接管理、表名处理与分页查询等辅助方法。
Index ¶
- type FindPageOptions
- type Instance
- func (c *Instance) AddError(err error)
- func (c *Instance) Debug() *Instance
- func (c *Instance) Error() []error
- func (c *Instance) FindForPage(model interface{}, options *FindPageOptions) (jcbaseGo.ListData, error)
- func (c *Instance) GetAllTableName() (tableNames []string, err error)
- func (c *Instance) GetConf() interface{}
- func (c *Instance) GetDb() *gorm.DB
- func (c *Instance) TableName(tableName *string, quotes ...bool) *Instance
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FindPageOptions ¶ added in v0.11.1
type FindPageOptions struct {
// 查询配置
Page int `default:"1"` // 页码,默认 1
PageSize int `default:"10"` // 分页大小,默认 10,最大 1000
ShowDeleted bool `default:"false"` // 是否显示软删除数据,默认 false
// 模型配置
PkId string `default:"id"` // 主键字段名,默认 "id"
ModelTableAlias string `default:""` // 模型表别名,默认为表名
// 回调
ListQuery func(*gorm.DB) *gorm.DB // 可选,自定义查询回调
ListSelect func(*gorm.DB) *gorm.DB // 可选,自定义查询字段回调
ListOrder func() interface{} // 可选,自定义排序回调
ListEach func(interface{}) interface{} // 可选,自定义遍历回调
ListReturn func(jcbaseGo.ListData) jcbaseGo.ListData // 可选,自定义返回回调
}
FindPageOptions 定义分页查询选项,语义与 CRUD list 保持一致;
type Instance ¶
type Instance struct {
Conf jcbaseGo.SqlLiteStruct
Db *gorm.DB
Errors []error
// contains filtered or unexported fields
}
Instance 表示 SQLite 连接实例,封装数据库配置、连接句柄、调试状态与错误收集。
func New ¶
func New(Conf jcbaseGo.SqlLiteStruct, opts ...string) (i *Instance)
New 创建一个 SQLite 实例并建立数据库连接; 可通过可选参数 `opts[0]` 指定配置别名以存入环境变量。
func (*Instance) FindForPage ¶ added in v0.11.1
func (c *Instance) FindForPage(model interface{}, options *FindPageOptions) (jcbaseGo.ListData, error)
FindForPage 按分页选项查询并返回列表数据;
func (*Instance) GetAllTableName ¶
GetAllTableName 查询并返回当前数据库中的所有表名。
func (*Instance) GetConf ¶ added in v0.10.2
func (c *Instance) GetConf() interface{}
GetConf 返回当前实例的原始配置结构。
Click to show internal directories.
Click to hide internal directories.