mysql

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: MIT Imports: 9 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearData4str

func ClearData4str(str string) string

清洗特殊字符串,目前有: 1. 单引号转义(批量插入时报错)

func DoBatchInsert

func DoBatchInsert(tableName string, data interface{}, db *gorm.DB) error

data must be slice

func EnumAnObjFieldNames

func EnumAnObjFieldNames(rv reflect.Type, cb func(f reflect.StructField))

迭代一个对象的所有字段名

func GetDataByPageAndPerPage added in v0.0.11

func GetDataByPageAndPerPage(db *gorm.DB, page int, perPage int, m interface{}, result interface{}) (totalPages int, totalCount int)

获取分页页数总数及数据列表。m是查询的表的model,result是列表结果传指针进来!

func GetOffset added in v0.0.11

func GetOffset(page int, perPage int) int

获取offset

func StrSliceContains

func StrSliceContains(strs []string, str string) bool

看一个数组中是否含有某个元素

Types

type BatchInsertSql

type BatchInsertSql struct {
	TableName string
	// 保存了属性信息,可以在组装sql时根据属性做不同的操作
	Fields    []reflect.StructField
	InsertSql string
	// contains filtered or unexported fields
}

批量插入组装sql

func NewBatchInsertSql

func NewBatchInsertSql(tableName string) *BatchInsertSql

每次批量插入都要new一个

func (*BatchInsertSql) Add

func (b *BatchInsertSql) Add(obj interface{})

func (*BatchInsertSql) ResultSql

func (b *BatchInsertSql) ResultSql() string

type DB

type DB interface {
	GetDB() *gorm.DB
	ClearAllData()
	Create(value interface{}) error
}

func MakeDB

func MakeDB(dbConfig *db_config.DbConfig) DB

type DBUtil

type DBUtil interface {
	CreateDB()
	DropDB()
	GetUtilDB() *gorm.DB
}

func MakeDBUtil

func MakeDBUtil(dbConfig *db_config.DbConfig) DBUtil

Jump to

Keyboard shortcuts

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