db_operations

package
v0.2.14 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDBRecordHasExist = errors.New("记录已存在")
	ErrDBRecordNotExist = errors.New("记录不存在")
)

Functions

func DestroyOperation

func DestroyOperation(op *Operations) error

func IsErrorDBRecordHasExist added in v0.2.8

func IsErrorDBRecordHasExist(err error) bool

func IsErrorDBRecordNotExist added in v0.2.8

func IsErrorDBRecordNotExist(err error) bool

Types

type BaseDBOperations

type BaseDBOperations interface {
	// 会重置数据库连接的方法
	Table(name string, args ...any) DBOperations

	// 会重置数据库连接的方法,一般配合Raw使用
	NewSession() DBOperations

	// 执行SQL语句,使用Raw之后,为了触发SQL执行,需要调用Row或者Rows
	// 如果是查询语句,使用Rows或Row均可,主要看自己需要查询的是单行还是多行
	// 如果是写语句,必须使用Rows,否则由于没有返回结果,Rows会报错
	// 使用Raw以后,所有分页相关的参数都无效,需要使用SQL语句进行分页
	Raw(sql string, values ...any) DBOperations

	// 组织SQL语句相关的方法
	Select(query string, args ...any) DBOperations
	Joins(query string, args ...any) DBOperations
	Where(conditions *Conditions) DBOperations
	Or(conditions *Conditions) DBOperations
	Having(conditions *Conditions) DBOperations
	GroupBy(groupBy string) DBOperations
	OrderBy(orderBy string) DBOperations
	Paging(pageNo int, pageSize int) DBOperations

	// 写方法
	Create(tableRow *TableRow) error
	CreateBatch(tableRows []TableRow) error
	Delete() error
	Updates(newTableRow *TableRow) error
	UpdatesWithRowsAffected(newTableRow *TableRow) (int64, error)

	// 查询方法
	Rows(pageNo int, pageSize int) ([]TableRow, error)
	Row() (*TableRow, error)

	// 其他方法
	Count(count *int64) error
	CheckExist() (bool, error)
	CheckHasOnlyOne() (bool, error)
}

type Conditions added in v0.2.10

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

func NewConditions added in v0.2.10

func NewConditions() *Conditions

func (*Conditions) Equal added in v0.2.10

func (clause *Conditions) Equal(columnName string, value any) *Conditions

func (*Conditions) GreaterThan added in v0.2.10

func (clause *Conditions) GreaterThan(columnName string, value any) *Conditions

func (*Conditions) GreaterThanAndEqual added in v0.2.10

func (clause *Conditions) GreaterThanAndEqual(columnName string, value any) *Conditions

func (*Conditions) In added in v0.2.10

func (clause *Conditions) In(columnName string, value any) *Conditions

func (*Conditions) LessThan added in v0.2.10

func (clause *Conditions) LessThan(columnName string, value any) *Conditions

func (*Conditions) LessThanAndEqual added in v0.2.10

func (clause *Conditions) LessThanAndEqual(columnName string, value any) *Conditions

func (*Conditions) Like added in v0.2.10

func (clause *Conditions) Like(columnName string, value any) *Conditions

func (*Conditions) Not added in v0.2.10

func (clause *Conditions) Not(columnName string, value any) *Conditions

func (*Conditions) NotIn added in v0.2.10

func (clause *Conditions) NotIn(columnName string, value any) *Conditions

type DBConfig

type DBConfig struct {
	Type               string `mapstructure:"type"`
	UserName           string `mapstructure:"user_name"`
	Password           string `mapstructure:"password"`
	Address            string `mapstructure:"address"`
	Port               string `mapstructure:"port"`
	Database           string `mapstructure:"database"`
	MaxConnections     int    `mapstructure:"max_connections"`
	MaxIdleConnections int    `mapstructure:"max_idle_connections"`
}

type DBOperations

type DBOperations interface {
	BeginTransaction() TransactionDBOperations
	// BeginEvent() EventDBOperations
	BaseDBOperations
}

type EventDBOperations added in v0.2.4

type EventDBOperations interface {
	RollbackEvent()
	CommitEvent()
	// TODO 需要重新定义创建等方法,传递必要的key
	EventRows(table string, keys []string, pageSize int, pageNo string)
	Replay(table string, keys []string)
}

type Operations

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

func NewOperations

func NewOperations(dbConfig *DBConfig) (*Operations, error)

func NewOperationsFromMap

func NewOperationsFromMap(configMap map[string]any) (*Operations, error)

func (*Operations) BeginTransaction

func (op *Operations) BeginTransaction() TransactionDBOperations

func (*Operations) CheckExist added in v0.2.9

func (op *Operations) CheckExist() (bool, error)

func (*Operations) CheckHasOnlyOne added in v0.2.9

func (op *Operations) CheckHasOnlyOne() (bool, error)

func (*Operations) Count

func (op *Operations) Count(count *int64) error

func (*Operations) Create

func (op *Operations) Create(tableRow *TableRow) error

func (*Operations) CreateBatch added in v0.2.4

func (op *Operations) CreateBatch(tableRows []TableRow) error

func (*Operations) Delete

func (op *Operations) Delete() error

func (*Operations) GroupBy

func (op *Operations) GroupBy(groupBy string) DBOperations

func (*Operations) Having

func (op *Operations) Having(conditions *Conditions) DBOperations

func (*Operations) Joins

func (op *Operations) Joins(query string, args ...any) DBOperations

func (*Operations) NewSession

func (op *Operations) NewSession() DBOperations

func (*Operations) Or

func (op *Operations) Or(conditions *Conditions) DBOperations

func (*Operations) OrderBy

func (op *Operations) OrderBy(orderBy string) DBOperations

func (*Operations) Paging

func (op *Operations) Paging(pageNo int, pageSize int) DBOperations

func (*Operations) Raw

func (op *Operations) Raw(sql string, values ...any) DBOperations

func (*Operations) Row

func (op *Operations) Row() (*TableRow, error)

func (*Operations) Rows

func (op *Operations) Rows(pageNo int, pageSize int) ([]TableRow, error)

func (*Operations) Select

func (op *Operations) Select(query string, args ...any) DBOperations

func (*Operations) Table

func (op *Operations) Table(name string, args ...any) DBOperations

func (*Operations) Updates

func (op *Operations) Updates(newTableRow *TableRow) error

func (*Operations) UpdatesWithRowsAffected

func (op *Operations) UpdatesWithRowsAffected(newTableRow *TableRow) (int64, error)

func (*Operations) Where

func (op *Operations) Where(conditions *Conditions) DBOperations

type TableRow added in v0.2.5

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

func NewTableRow added in v0.2.5

func NewTableRow() *TableRow

func NewTableRowFromMap added in v0.2.5

func NewTableRowFromMap(m map[string]any) *TableRow

func (*TableRow) AddColumnValueBool added in v0.2.5

func (tableRow *TableRow) AddColumnValueBool(columnName string, value bool) *TableRow

func (*TableRow) AddColumnValueBytes added in v0.2.5

func (tableRow *TableRow) AddColumnValueBytes(columnName string, value []byte) *TableRow

func (*TableRow) AddColumnValueFloat32 added in v0.2.5

func (tableRow *TableRow) AddColumnValueFloat32(columnName string, value float32) *TableRow

func (*TableRow) AddColumnValueFloat64 added in v0.2.5

func (tableRow *TableRow) AddColumnValueFloat64(columnName string, value float64) *TableRow

func (*TableRow) AddColumnValueInt added in v0.2.5

func (tableRow *TableRow) AddColumnValueInt(columnName string, value int) *TableRow

func (*TableRow) AddColumnValueInt16 added in v0.2.5

func (tableRow *TableRow) AddColumnValueInt16(columnName string, value int16) *TableRow

func (*TableRow) AddColumnValueInt32 added in v0.2.5

func (tableRow *TableRow) AddColumnValueInt32(columnName string, value int32) *TableRow

func (*TableRow) AddColumnValueInt64 added in v0.2.5

func (tableRow *TableRow) AddColumnValueInt64(columnName string, value int64) *TableRow

func (*TableRow) AddColumnValueInt8 added in v0.2.5

func (tableRow *TableRow) AddColumnValueInt8(columnName string, value int8) *TableRow

func (*TableRow) AddColumnValueString added in v0.2.5

func (tableRow *TableRow) AddColumnValueString(columnName string, value string) *TableRow

func (*TableRow) AddColumnValueTime added in v0.2.5

func (tableRow *TableRow) AddColumnValueTime(columnName string, value time.Time) *TableRow

func (*TableRow) AddColumnValueUint added in v0.2.5

func (tableRow *TableRow) AddColumnValueUint(columnName string, value uint) *TableRow

func (*TableRow) AddColumnValueUint16 added in v0.2.5

func (tableRow *TableRow) AddColumnValueUint16(columnName string, value uint16) *TableRow

func (*TableRow) AddColumnValueUint32 added in v0.2.5

func (tableRow *TableRow) AddColumnValueUint32(columnName string, value uint32) *TableRow

func (*TableRow) AddColumnValueUint64 added in v0.2.5

func (tableRow *TableRow) AddColumnValueUint64(columnName string, value uint64) *TableRow

func (*TableRow) AddColumnValueUint8 added in v0.2.5

func (tableRow *TableRow) AddColumnValueUint8(columnName string, value uint8) *TableRow

func (*TableRow) ColumnValueBool added in v0.2.5

func (tableRow *TableRow) ColumnValueBool(columnName string) bool

func (*TableRow) ColumnValueBytes added in v0.2.5

func (tableRow *TableRow) ColumnValueBytes(columnName string) []byte

func (*TableRow) ColumnValueFloat32 added in v0.2.5

func (tableRow *TableRow) ColumnValueFloat32(columnName string) float32

func (*TableRow) ColumnValueFloat64 added in v0.2.5

func (tableRow *TableRow) ColumnValueFloat64(columnName string) float64

func (*TableRow) ColumnValueInt added in v0.2.5

func (tableRow *TableRow) ColumnValueInt(columnName string) int

func (*TableRow) ColumnValueInt16 added in v0.2.5

func (tableRow *TableRow) ColumnValueInt16(columnName string) int16

func (*TableRow) ColumnValueInt32 added in v0.2.5

func (tableRow *TableRow) ColumnValueInt32(columnName string) int32

func (*TableRow) ColumnValueInt64 added in v0.2.5

func (tableRow *TableRow) ColumnValueInt64(columnName string) int64

func (*TableRow) ColumnValueInt8 added in v0.2.5

func (tableRow *TableRow) ColumnValueInt8(columnName string) int8

func (*TableRow) ColumnValueString added in v0.2.5

func (tableRow *TableRow) ColumnValueString(columnName string) string

func (*TableRow) ColumnValueTime added in v0.2.5

func (tableRow *TableRow) ColumnValueTime(columnName string) time.Time

func (*TableRow) ColumnValueUint added in v0.2.5

func (tableRow *TableRow) ColumnValueUint(columnName string) uint

func (*TableRow) ColumnValueUint16 added in v0.2.5

func (tableRow *TableRow) ColumnValueUint16(columnName string) uint16

func (*TableRow) ColumnValueUint32 added in v0.2.5

func (tableRow *TableRow) ColumnValueUint32(columnName string) uint32

func (*TableRow) ColumnValueUint64 added in v0.2.5

func (tableRow *TableRow) ColumnValueUint64(columnName string) uint64

func (*TableRow) ColumnValueUint8 added in v0.2.5

func (tableRow *TableRow) ColumnValueUint8(columnName string) uint8

func (*TableRow) Empty added in v0.2.7

func (tableRow *TableRow) Empty() bool

func (*TableRow) Len added in v0.2.6

func (tableRow *TableRow) Len() int

func (*TableRow) ToMap added in v0.2.5

func (tableRow *TableRow) ToMap() map[string]any

type TransactionDBOperations

type TransactionDBOperations interface {
	BaseDBOperations
	RollbackTransaction()
	CommitTransaction()
}

type TransactionOperations

type TransactionOperations struct {
	Operations
}

func (*TransactionOperations) CommitTransaction

func (op *TransactionOperations) CommitTransaction()

func (*TransactionOperations) RollbackTransaction

func (op *TransactionOperations) RollbackTransaction()

Jump to

Keyboard shortcuts

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