mysql

package
v0.0.0-...-620b1b6 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 顺序排序
	AscOrder = "asc"
	// 倒序排序
	DescOrder = "desc"

	// 默认排序字段
	DefaultOrderField = "modified"
	OrderFieldCreated = "created"

	// 批量创建的每条sql最大条数
	CreateBatchSize = 500
	// 批量更新的每条sql最大条数
	UpdateBatchSize = 10000
)

Variables

This section is empty.

Functions

func BuildCommonCondition

func BuildCommonCondition(tx *gorm.DB, obj interface{}, req dtos.BaseSearchConditionQuery) *gorm.DB

func MakeLikeParams

func MakeLikeParams(str string) string

Types

type ClientSQLite

type ClientSQLite interface {
	CloseSession()

	// 关闭连接
	Close()
	// 初始化建表操作
	InitTable(dos ...DataObject) error
	// 添加数据
	CreateObject(do DataObject) error
	// 判断数据是否存在
	ExistObject(do DataObject) (bool, error)
	// 删除数据
	DeleteObject(do DataObject) error
	// 更新数据
	UpdateObject(do DataObject) error
	// 关联更新
	AssociationsUpdateObject(do DataObject) error
	// 关联删除
	AssociationsDeleteObject(do DataObject) error
	// 查询单个数据
	GetObject(doCond DataObject, do DataObject) error
	// 预加载查询单个数据
	GetPreloadObject(doCond DataObject, do DataObject) error
	// 查询列表数据
	GetObjects(doCond DataObject, do DataObject, likeParam *LikeQueryParam,
		order *OrderQueryParam, offset, limit int) ([]interface{}, int64, error)
	// 批量更新数据
	BatchUpdate(fields, conflictFields, updateFields []string, tableName string, records [][]interface{}) error

	//事物相关
	ExecSqlWithTransaction(funcs ...func(db *gorm.DB) error) error
}

type DataObject

type DataObject interface {
	TableName() string
	Get() interface{}
}

type DialectorType

type DialectorType string
const (
	DIALECTOR_MYSQL  DialectorType = "mysql"
	DIALECTOR_PGSQL  DialectorType = "postgres"
	DIALECTOR_SQLITE DialectorType = "sqlite"
)

type GormClient

type GormClient struct {
	Pool *gorm.DB
}

func NewGormClient

func NewGormClient(config dtos.Configuration, lc logger.LoggingClient) (*GormClient, error)

func (*GormClient) AssociationsDeleteObject

func (c *GormClient) AssociationsDeleteObject(object DataObject) (err error)

AssociationsDeleteObject 关联删除

func (*GormClient) AssociationsUpdateObject

func (c *GormClient) AssociationsUpdateObject(object DataObject) (err error)

AssociationsUpdateObject 关联更新

func (*GormClient) BatchUpdate

func (c *GormClient) BatchUpdate(fields, conflictFields, updateFields []string, tableName string, records [][]interface{}) error

fields: 全字段名称列表 conflictFields: 唯一字段名称列表 updateFields: 更新字段名称列表 record: 更新数据列表

func (*GormClient) Close

func (c *GormClient) Close()

func (*GormClient) CloseSession

func (c *GormClient) CloseSession()

func (*GormClient) CreateObject

func (c *GormClient) CreateObject(object DataObject) (err error)

CreateObject 添加

func (*GormClient) DeleteObject

func (c *GormClient) DeleteObject(object DataObject) (err error)

DeleteObject 删除

func (*GormClient) ExecSqlWithTransaction

func (c *GormClient) ExecSqlWithTransaction(funcs ...func(db *gorm.DB) error) error

func (*GormClient) ExistObject

func (c *GormClient) ExistObject(do DataObject) (exist bool, err error)

判断是否存在

func (*GormClient) GetObject

func (c *GormClient) GetObject(obCond DataObject, object DataObject) (err error)

GetObject 获取结果

func (*GormClient) GetObjects

func (c *GormClient) GetObjects(doCond DataObject, do DataObject, likeParam *LikeQueryParam, order *OrderQueryParam, offset, limit int) (list []interface{}, count int64, err error)

条件查询

func (*GormClient) GetPreloadObject

func (c *GormClient) GetPreloadObject(obCond DataObject, object DataObject) (err error)

GetPreloadObject 预加载

func (*GormClient) InitTable

func (c *GormClient) InitTable(dos ...DataObject) error

func (*GormClient) UpdateObject

func (c *GormClient) UpdateObject(object DataObject) (err error)

UpdateObject 更新数据

type GormWriter

type GormWriter struct {
	// contains filtered or unexported fields
}

func (*GormWriter) Printf

func (gl *GormWriter) Printf(s string, values ...interface{})

type LikeQueryParam

type LikeQueryParam struct {
	Field  string
	Value  string
	Prefix bool
	Suffix bool
}

模糊查询参数

type OrderQueryParam

type OrderQueryParam struct {
	Key  string
	Desc bool
}

排序查询参数

func NewDefaultOrderQueryParam

func NewDefaultOrderQueryParam() *OrderQueryParam

默认按照最后修改时间进行逆序排序

Jump to

Keyboard shortcuts

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