Documentation ¶
Index ¶
- Constants
- Variables
- func GeneralListGORM(database *gorm.DB, params *ListByPageParams) (db *gorm.DB)
- func GetTablePrimaryKeys(db *gorm.DB, tableName string) (keys []string)
- func InOperationUint8(fieldName string, values []uint8, isIn bool) string
- func IsGormTx(db *gorm.DB) (err error)
- func TransactionGORM(db *gorm.DB, f TransactionFuncGORM) (data interface{}, err error)
- type Condition
- type ConditionItem
- type GormDAO
- type ListByPageParams
- type Tabler
- type TransactionFuncGORM
Constants ¶
View Source
const ( OpEqual = "eq" // 等于 OpNotEqual = "ne" // 不等于 OpLessThan = "lt" // 小于 OpLessThanEqual = "lte" // 小于等于 OpGreaterThan = "gt" // 大于 OpGreaterThanEqual = "gte" // 大于等于 OpIn = "in" // 包含 OpLike = "lk" // 模糊查询 OpCustom = "cm" // 完全自定义SQL语句 )
操作符
View Source
const ( ConnAnd = "and" // 与 ConnOr = "or" // 或 )
连接符
Variables ¶
View Source
var TableMap = make(map[string]interface{})
记录表名称和对应的Item项的映射关系
Functions ¶
func GeneralListGORM ¶
func GeneralListGORM(database *gorm.DB, params *ListByPageParams) (db *gorm.DB)
func GetTablePrimaryKeys ¶
获取表的主键列表
func InOperationUint8 ¶
由于xxx in/not in (?)时,如果值数组是uint8数组,则GORM会按照字符串处理
func TransactionGORM ¶
func TransactionGORM(db *gorm.DB, f TransactionFuncGORM) (data interface{}, err error)
GORM事务处理
Types ¶
type Condition ¶
type Condition struct { Subs []Condition `json:"subs"` // 复合条件项 Items []ConditionItem `json:"items"` // 原子级条件项 Conn string `json:"conn"` // 连接符 }
复合条件项
type ConditionItem ¶
type ConditionItem struct { Left string `json:"left"` // 左值,一般为列名称 Right interface{} `json:"right"` // 右值,一般为比较数值 Op string `json:"op"` }
原子级条件项
func (ConditionItem) QuerySql ¶
func (m ConditionItem) QuerySql() (whereSql string, whereArgs []interface{}, err error)
type GormDAO ¶
type GormDAO struct {
// contains filtered or unexported fields
}
func (*GormDAO) AddUniqueIndex ¶
type ListByPageParams ¶
type ListByPageParams struct { Fields []string `json:"fields"` // 查询的字段,若为空数组,则查询全部字段 IgnoreFields []string `json:"ignore_fields"` // 忽略掉哪些字段 PageNumber uint64 `json:"page_number"` // 从1开始的页码 PageSize uint64 `json:"page_size"` // 大于1为有效的页大小 SortBy string `json:"sort_by"` // 按哪个字段名称排序 SortDirection bool `json:"sort_direction"` // true为ASC,false为DESC }
分页查询列表的公共参数
Source Files ¶
Click to show internal directories.
Click to hide internal directories.