dbtool

package
v0.0.0-...-82269be Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

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 GetTablePrimaryKeys(db *gorm.DB, tableName string) (keys []string)

获取表的主键列表

func InOperationUint8

func InOperationUint8(
	fieldName string,
	values []uint8,
	isIn bool,
) string

由于xxx in/not in (?)时,如果值数组是uint8数组,则GORM会按照字符串处理

func IsGormTx

func IsGormTx(db *gorm.DB) (err error)

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"`  // 连接符
}

复合条件项

func (Condition) Fields

func (m Condition) Fields() (result []string)

func (Condition) QuerySql

func (m Condition) QuerySql() (whereSql string, whereArgs []interface{}, err error)

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) AddIndex

func (m *GormDAO) AddIndex(fields ...string)

func (*GormDAO) AddUniqueIndex

func (m *GormDAO) AddUniqueIndex(fields ...string)

func (*GormDAO) Init

func (m *GormDAO) Init(db *gorm.DB, item Tabler)

func (*GormDAO) ValidDB

func (m *GormDAO) ValidDB(db *gorm.DB) *gorm.DB

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
}

分页查询列表的公共参数

type Tabler

type Tabler interface {
	TableName() string
}

type TransactionFuncGORM

type TransactionFuncGORM func(*gorm.DB) (interface{}, error)

事务实际操作函数

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL