dbUtils

package
v0.0.0-...-9966579 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: MulanPSL-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSearchRequest

func NewSearchRequest(pageIndex int, pageSize int) searchRequest

func ToInterfaceArray

func ToInterfaceArray(source interface{}) []interface{}

Types

type BaseDao

type BaseDao struct {
	TableName string
	Prefix    string
	Dbkey     string

	Session *xorm.Session

	DisableSyncDb bool
	// contains filtered or unexported fields
}

func NewBaseDao

func NewBaseDao(tableName string) *BaseDao

func (*BaseDao) BatchInsert

func (dao *BaseDao) BatchInsert(beans interface{}) (int64, error)

func (*BaseDao) BeginTrans

func (dao *BaseDao) BeginTrans() error

func (*BaseDao) Close

func (dao *BaseDao) Close() error

func (*BaseDao) Commit

func (dao *BaseDao) Commit() error

func (*BaseDao) ContinueTrans

func (dao *BaseDao) ContinueTrans(session *xorm.Session)

func (*BaseDao) DeleteAll

func (dao *BaseDao) DeleteAll() error

func (*BaseDao) DeleteById

func (dao *BaseDao) DeleteById(id int64) error

func (*BaseDao) EnableSyncDb

func (dao *BaseDao) EnableSyncDb() bool

func (*BaseDao) ExecuteSql

func (dao *BaseDao) ExecuteSql(sql string, args []interface{}) error

func (*BaseDao) Find

func (dao *BaseDao) Find(beansPtr interface{}, sql string, args ...interface{}) error

func (*BaseDao) GetById

func (dao *BaseDao) GetById(id interface{}, bean interface{}) (bool, error)

func (*BaseDao) GetDbHelper

func (dao *BaseDao) GetDbHelper() *xorm.Engine

func (*BaseDao) GetLikeStr

func (dao *BaseDao) GetLikeStr(string2 string) string

func (*BaseDao) Insert

func (dao *BaseDao) Insert(bean interface{}) (int64, error)

func (*BaseDao) InsertByTableName

func (dao *BaseDao) InsertByTableName(bean interface{}, tableName string) (int64, error)

func (*BaseDao) Queryable

func (dao *BaseDao) Queryable() IQueryable

func (*BaseDao) Rollback

func (dao *BaseDao) Rollback() error

func (*BaseDao) SearchByPage

func (dao *BaseDao) SearchByPage(sql string, request searchRequest, listPtr interface{}) *helper.QueryResult

func (*BaseDao) SelectAll

func (dao *BaseDao) SelectAll(beans interface{}) error

func (*BaseDao) SetTableName

func (dao *BaseDao) SetTableName(tableName string)

func (*BaseDao) Update

func (dao *BaseDao) Update(i interface{}) (int64, error)

type BaseDao2

type BaseDao2 struct {
	Prefix string
	Dbkey  string

	DisableSyncDb bool
	// contains filtered or unexported fields
}

func NewBaseDao2

func NewBaseDao2() *BaseDao2

func (*BaseDao2) BatchInsert

func (dao *BaseDao2) BatchInsert(beans interface{}, tableName string, ctx context.Context) (int64, error)

func (*BaseDao2) BeginTrans

func (dao *BaseDao2) BeginTrans(ctx context.Context) (error, context.Context)

func (*BaseDao2) Close

func (dao *BaseDao2) Close() error

func (*BaseDao2) Commit

func (dao *BaseDao2) Commit(ctx context.Context) error

func (*BaseDao2) DeleteAll

func (dao *BaseDao2) DeleteAll(tableName string, ctx context.Context) error

func (*BaseDao2) DeleteById

func (dao *BaseDao2) DeleteById(id int64, tableName string, ctx context.Context) error

func (*BaseDao2) EnableSyncDb

func (dao *BaseDao2) EnableSyncDb() bool

func (*BaseDao2) ExecuteSql

func (dao *BaseDao2) ExecuteSql(sql string, args []interface{}, ctx context.Context) error

func (*BaseDao2) GetById

func (dao *BaseDao2) GetById(id interface{}, bean interface{}, tableName string, ctx context.Context) (bool, error)

func (*BaseDao2) GetDbHelper

func (dao *BaseDao2) GetDbHelper() *xorm.Engine

func (*BaseDao2) GetLikeStr

func (dao *BaseDao2) GetLikeStr(string2 string) string

func (*BaseDao2) Insert

func (dao *BaseDao2) Insert(bean interface{}, tableName string, ctx context.Context) (int64, error)

func (*BaseDao2) InsertByTableName

func (dao *BaseDao2) InsertByTableName(bean interface{}, tableName string, ctx context.Context) (int64, error)

func (*BaseDao2) Queryable

func (dao *BaseDao2) Queryable() IQueryable2

func (*BaseDao2) Rollback

func (dao *BaseDao2) Rollback(ctx context.Context) error

func (*BaseDao2) SearchByPage

func (dao *BaseDao2) SearchByPage(sql string, request searchRequest, listPtr interface{}, ctx context.Context) *helper.QueryResult

func (*BaseDao2) SelectAll

func (dao *BaseDao2) SelectAll(beans interface{}, ctx context.Context) error

func (*BaseDao2) Update

func (dao *BaseDao2) Update(i interface{}, tableName string, ctx context.Context) (int64, error)

type DbHelper

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

func NewDbHelper

func NewDbHelper() *DbHelper

func (*DbHelper) GetDbByDbConfig

func (db *DbHelper) GetDbByDbConfig(dbConfig *gcore.DbConfig) *xorm.Engine

func (*DbHelper) GetDbByKey

func (db *DbHelper) GetDbByKey(dbKey string) *xorm.Engine

func (*DbHelper) GetDbConfig

func (db *DbHelper) GetDbConfig(dbKey string) *gcore.DbConfig

func (*DbHelper) GetDialect

func (db *DbHelper) GetDialect(dbKey string) string

func (*DbHelper) GetEngineKey

func (db *DbHelper) GetEngineKey(dbConfig *gcore.DbConfig) string

func (*DbHelper) GetReadDb

func (db *DbHelper) GetReadDb() *xorm.Engine

func (*DbHelper) GetTargetDbConfig

func (db *DbHelper) GetTargetDbConfig(dbKey string) *gcore.DbConfig

func (*DbHelper) GetWriteDb

func (db *DbHelper) GetWriteDb() *xorm.Engine

type DbLogContent

type DbLogContent struct {
	DataBase     string
	DataBaseKey  string
	TableName    string
	Fields       []string
	RecordValues []interface{}

	WhereFields      []string
	WhereFieldValues []interface{}

	HasAutoIncr bool
	HasPkField  bool
	Sql         string
	LogType     DbLogType
	LogTime     dateTime.DateTime
}

type DbLogHelper

type DbLogHelper struct {
	FileNameTemp string
	FileName     string

	FileIndex       int
	MaxFileSize     int64
	MaxWriteSeconds float64
	FileLock        sync.Mutex
}

func NewDbLogHelper

func NewDbLogHelper() *DbLogHelper

func (*DbLogHelper) CheckNewFile

func (d *DbLogHelper) CheckNewFile(fl *os.File) bool

func (*DbLogHelper) GetLatestFileIndex

func (d *DbLogHelper) GetLatestFileIndex() int

func (*DbLogHelper) GetOldFirstFilePath

func (d *DbLogHelper) GetOldFirstFilePath() (string, error)

func (*DbLogHelper) WriteDbLog

func (d *DbLogHelper) WriteDbLog(logContent *DbLogContent) error

func (*DbLogHelper) WriteDeletedLog

func (d *DbLogHelper) WriteDeletedLog(table string, whereFields []string, whereFieldsValue []interface{}, dataBase string, dataBaseKey string) error

func (*DbLogHelper) WriteDeletedLogByEntity

func (d *DbLogHelper) WriteDeletedLogByEntity(log interface{}, dataBase string, dataBaseKey string) error

func (*DbLogHelper) WriteExecuteSqlLog

func (d *DbLogHelper) WriteExecuteSqlLog(sql string, args []interface{}, dataBase string, dataBaseKey string) error

func (*DbLogHelper) WriteInsertedLog

func (d *DbLogHelper) WriteInsertedLog(log interface{}, tableName string, dataBase string, dataBaseKey string) error

func (*DbLogHelper) WriteUpdatedLog

func (d *DbLogHelper) WriteUpdatedLog(table string, fields []string, fieldValues []interface{}, whereFields []string, whereFieldsValue []interface{}, dataBase string, dataBaseKey string) error

func (*DbLogHelper) WriteUpdatedLogByEntity

func (d *DbLogHelper) WriteUpdatedLogByEntity(log interface{}, tableName string, dataBase string, dataBaseKey string) error

type DbLogSender

type DbLogSender struct {
	MaxIndex int
	// contains filtered or unexported fields
}

func NewDbLogSender

func NewDbLogSender() *DbLogSender

func (*DbLogSender) GetHeaderBytes

func (d *DbLogSender) GetHeaderBytes(head SendHead) ([]byte, error)

func (*DbLogSender) GetOldFirstFilePath

func (d *DbLogSender) GetOldFirstFilePath() (string, error)

func (*DbLogSender) Send

func (d *DbLogSender) Send(bytes []byte) error

func (*DbLogSender) StartSendFile

func (d *DbLogSender) StartSendFile()

type DbLogType

type DbLogType int
const (
	Insert     DbLogType = 0
	Update     DbLogType = 1
	Delete     DbLogType = 2
	ExecuteSql DbLogType = 3
)

type DbParseHelper

type DbParseHelper struct {
}

func NewDbParseHelper

func NewDbParseHelper() *DbParseHelper

func (*DbParseHelper) ParseDbLog

func (d *DbParseHelper) ParseDbLog(fileName string) ([]*DbLogContent, error)

type DbSyncClient

type DbSyncClient struct {
}

func NewDbSyncClient

func NewDbSyncClient() *DbSyncClient

func (*DbSyncClient) ReplayDbLog

func (d *DbSyncClient) ReplayDbLog(log *DbLogContent)

func (*DbSyncClient) ReplayDeleteRecord

func (d *DbSyncClient) ReplayDeleteRecord(logContent *DbLogContent)

ReplayDeleteRecord 重放删除

func (*DbSyncClient) ReplayExecuteSql

func (d *DbSyncClient) ReplayExecuteSql(logContent *DbLogContent)

func (*DbSyncClient) ReplayInsertRecord

func (d *DbSyncClient) ReplayInsertRecord(logContent *DbLogContent)

ReplayInsertRecord 重放插入

func (*DbSyncClient) ReplayUpdateRecord

func (d *DbSyncClient) ReplayUpdateRecord(logContent *DbLogContent)

ReplayUpdateRecord 重放更新记录

func (*DbSyncClient) StartSyncDbData

func (d *DbSyncClient) StartSyncDbData()

type DbWrapper

type DbWrapper struct {
	Session *xorm.Session
	Dbkey   string
	Prefix  string
	// contains filtered or unexported fields
}

func (*DbWrapper) Find

func (dao *DbWrapper) Find(beans interface{}, condiBeans ...interface{}) error

func (*DbWrapper) GetDbHelper

func (dao *DbWrapper) GetDbHelper() *xorm.Engine

type IBaseDao

type IBaseDao interface {
	SelectAll(beans interface{})
	GetById(id int64, bean interface{})
	DeleteById(id int64) error
	GetLikeStr(val string) string
}

type IQueryable

type IQueryable interface {
	From(tableName string) IQueryable
	Take(size int32) IQueryable
	WhereIf(condition string, arg interface{}, condtion bool) IQueryable
	Where(condition string, arg interface{}) IQueryable
	WhereIn(fieldName string, args []interface{}, condition bool) IQueryable

	In(fieldName string, args ...interface{}) IQueryable
	Order(orderField string) IQueryable
	OrderByDesc(orderField string) IQueryable
	Page(pageIndex int, pageSize int, beansPtr interface{}) *helper.QueryResult
	List(beansPtr interface{}) error
	FirstOrDefault(beanPtr interface{}) error
	Delete() (int64, error)
	Count() (int64, error)
	Set(field string, arg interface{}) IQueryable
	Update() (bool, error)
	GetWhereMap() map[string]interface{}
	SelectFields(fields string) IQueryable
}

func NewMySqlQueryable

func NewMySqlQueryable() IQueryable

type IQueryable2

type IQueryable2 interface {
	From(tableName string) IQueryable2
	Take(size int32) IQueryable2
	WhereIf(condition string, arg interface{}, condtion bool) IQueryable2
	Where(condition string, arg interface{}) IQueryable2
	WhereIn(fieldName string, args []interface{}, condition bool) IQueryable2

	In(fieldName string, args ...interface{}) IQueryable2
	Order(orderField string) IQueryable2
	OrderByDesc(orderField string) IQueryable2
	Page(pageIndex int, pageSize int, beansPtr interface{}, ctx context.Context) *helper.QueryResult
	List(beansPtr interface{}, ctx context.Context)
	FirstOrDefault(beanPtr interface{}, ctx context.Context)
	Delete(ctx context.Context) int64
	Count(ctx context.Context) int64
	Set(field string, arg interface{}) IQueryable2
	Update(ctx context.Context) bool
	GetWhereMap() map[string]interface{}
	SelectFields(fields string) IQueryable2
}

type MsSqlQueryable

type MsSqlQueryable struct {
	IQueryable
	TableName string
	Prefix    string
	Dbkey     string
	WhereMap  map[string]interface{}
	OrderStr  strings.Builder

	SetMap map[string]interface{}

	QueryFields string
	// contains filtered or unexported fields
}

func (*MsSqlQueryable) Count

func (queryable *MsSqlQueryable) Count() (int64, error)

func (*MsSqlQueryable) Delete

func (queryable *MsSqlQueryable) Delete() (int64, error)

func (*MsSqlQueryable) FirstOrDefault

func (queryable *MsSqlQueryable) FirstOrDefault(beanPtr interface{}) error

func (*MsSqlQueryable) From

func (queryable *MsSqlQueryable) From(tableName string) IQueryable

func (*MsSqlQueryable) GetWhereMap

func (queryable *MsSqlQueryable) GetWhereMap() map[string]interface{}

func (*MsSqlQueryable) In

func (queryable *MsSqlQueryable) In(fieldName string, args ...interface{}) IQueryable

func (*MsSqlQueryable) List

func (queryable *MsSqlQueryable) List(beansPtr interface{}) error

func (*MsSqlQueryable) Order

func (queryable *MsSqlQueryable) Order(orderField string) IQueryable

func (*MsSqlQueryable) OrderByDesc

func (queryable *MsSqlQueryable) OrderByDesc(orderField string) IQueryable

func (*MsSqlQueryable) Page

func (queryable *MsSqlQueryable) Page(pageIndex int, pageSize int, beansPtr interface{}) *helper.QueryResult

func (*MsSqlQueryable) SelectFields

func (queryable *MsSqlQueryable) SelectFields(fields string) IQueryable

func (*MsSqlQueryable) Set

func (queryable *MsSqlQueryable) Set(field string, arg interface{}) IQueryable

func (*MsSqlQueryable) Take

func (queryable *MsSqlQueryable) Take(size int32) IQueryable

func (*MsSqlQueryable) Update

func (queryable *MsSqlQueryable) Update() (bool, error)

func (*MsSqlQueryable) Where

func (queryable *MsSqlQueryable) Where(condition string, arg interface{}) IQueryable

func (*MsSqlQueryable) WhereIf

func (queryable *MsSqlQueryable) WhereIf(condition string, arg interface{}, condtion bool) IQueryable

func (*MsSqlQueryable) WhereIn

func (queryable *MsSqlQueryable) WhereIn(fieldName string, args []interface{}, condition bool) IQueryable

type MsSqlQueryable2

type MsSqlQueryable2 struct {
	IQueryable2
	TableName string
	Prefix    string
	Dbkey     string
	WhereMap  map[string]interface{}
	OrderStr  strings.Builder

	SetMap map[string]interface{}

	QueryFields string
	// contains filtered or unexported fields
}

func (*MsSqlQueryable2) Count

func (queryable *MsSqlQueryable2) Count(ctx context.Context) int64

func (*MsSqlQueryable2) Delete

func (queryable *MsSqlQueryable2) Delete(ctx context.Context) int64

func (*MsSqlQueryable2) FirstOrDefault

func (queryable *MsSqlQueryable2) FirstOrDefault(beanPtr interface{}, ctx context.Context)

func (*MsSqlQueryable2) From

func (queryable *MsSqlQueryable2) From(tableName string) IQueryable2

func (*MsSqlQueryable2) GetWhereMap

func (queryable *MsSqlQueryable2) GetWhereMap() map[string]interface{}

func (*MsSqlQueryable2) In

func (queryable *MsSqlQueryable2) In(fieldName string, args ...interface{}) IQueryable2

func (*MsSqlQueryable2) List

func (queryable *MsSqlQueryable2) List(beansPtr interface{}, ctx context.Context)

func (*MsSqlQueryable2) Order

func (queryable *MsSqlQueryable2) Order(orderField string) IQueryable2

func (*MsSqlQueryable2) OrderByDesc

func (queryable *MsSqlQueryable2) OrderByDesc(orderField string) IQueryable2

func (*MsSqlQueryable2) Page

func (queryable *MsSqlQueryable2) Page(pageIndex int, pageSize int, beansPtr interface{}, ctx context.Context) *helper.QueryResult

func (*MsSqlQueryable2) SelectFields

func (queryable *MsSqlQueryable2) SelectFields(fields string) IQueryable2

func (*MsSqlQueryable2) Set

func (queryable *MsSqlQueryable2) Set(field string, arg interface{}) IQueryable2

func (*MsSqlQueryable2) Take

func (queryable *MsSqlQueryable2) Take(size int32) IQueryable2

func (*MsSqlQueryable2) Update

func (queryable *MsSqlQueryable2) Update(ctx context.Context) bool

func (*MsSqlQueryable2) Where

func (queryable *MsSqlQueryable2) Where(condition string, arg interface{}) IQueryable2

func (*MsSqlQueryable2) WhereIf

func (queryable *MsSqlQueryable2) WhereIf(condition string, arg interface{}, condtion bool) IQueryable2

func (*MsSqlQueryable2) WhereIn

func (queryable *MsSqlQueryable2) WhereIn(fieldName string, args []interface{}, condition bool) IQueryable2

type MySqlQueryable

type MySqlQueryable struct {
	IQueryable
	TableName string
	Prefix    string
	Dbkey     string
	WhereMap  map[string]interface{}
	OrderStr  strings.Builder

	SetMap map[string]interface{}

	QueryFields string
	// contains filtered or unexported fields
}

func (*MySqlQueryable) Count

func (queryable *MySqlQueryable) Count() (int64, error)

func (*MySqlQueryable) Delete

func (queryable *MySqlQueryable) Delete() (int64, error)

func (*MySqlQueryable) FirstOrDefault

func (queryable *MySqlQueryable) FirstOrDefault(beanPtr interface{}) error

func (*MySqlQueryable) From

func (dao *MySqlQueryable) From(tableName string) IQueryable

func (*MySqlQueryable) GetWhereMap

func (queryable *MySqlQueryable) GetWhereMap() map[string]interface{}

func (*MySqlQueryable) In

func (queryable *MySqlQueryable) In(fieldName string, args ...interface{}) IQueryable

func (*MySqlQueryable) List

func (queryable *MySqlQueryable) List(beansPtr interface{}) error

func (*MySqlQueryable) Order

func (dao *MySqlQueryable) Order(orderField string) IQueryable

func (*MySqlQueryable) OrderByDesc

func (dao *MySqlQueryable) OrderByDesc(orderField string) IQueryable

func (*MySqlQueryable) Page

func (queryable *MySqlQueryable) Page(pageIndex int, pageSize int, beansPtr interface{}) *helper.QueryResult

func (*MySqlQueryable) SelectFields

func (queryable *MySqlQueryable) SelectFields(fields string) IQueryable

func (*MySqlQueryable) Set

func (queryable *MySqlQueryable) Set(field string, arg interface{}) IQueryable

func (*MySqlQueryable) Take

func (dao *MySqlQueryable) Take(size int32) IQueryable

func (*MySqlQueryable) Update

func (queryable *MySqlQueryable) Update() (bool, error)

func (*MySqlQueryable) Where

func (dao *MySqlQueryable) Where(condition string, arg interface{}) IQueryable

func (*MySqlQueryable) WhereIf

func (dao *MySqlQueryable) WhereIf(condition string, arg interface{}, condtion bool) IQueryable

func (*MySqlQueryable) WhereIn

func (queryable *MySqlQueryable) WhereIn(fieldName string, args []interface{}, condition bool) IQueryable

type SendHead

type SendHead struct {
	SendType   uint32
	ContentLen uint32
}

type SendPacket

type SendPacket struct {
	Head    SendHead
	Content interface{}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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