Documentation ¶
Index ¶
- Variables
- func DestroyOperation(op *Operations) error
- type BaseDBOperations
- type Conditions
- func (clause *Conditions) Equal(columnName string, value any) *Conditions
- func (clause *Conditions) GreaterThan(columnName string, value any) *Conditions
- func (clause *Conditions) GreaterThanAndEqual(columnName string, value any) *Conditions
- func (clause *Conditions) In(columnName string, value any) *Conditions
- func (clause *Conditions) LessThan(columnName string, value any) *Conditions
- func (clause *Conditions) LessThanAndEqual(columnName string, value any) *Conditions
- func (clause *Conditions) Like(columnName string, value any) *Conditions
- func (clause *Conditions) Not(columnName string, value any) *Conditions
- func (clause *Conditions) NotIn(columnName string, value any) *Conditions
- type DBConfig
- type DBOperations
- type EventDBOperations
- type Operations
- func (op *Operations) AutoMigrate(tables ...Table) error
- func (op *Operations) BeginTransaction() TransactionDBOperations
- func (op *Operations) CheckExist() (bool, error)
- func (op *Operations) CheckHasOnlyOne() (bool, error)
- func (op *Operations) Count() (int64, error)
- func (op *Operations) Create(tableRow *TableRow) error
- func (op *Operations) CreateBatch(tableRows []TableRow) error
- func (op *Operations) Delete() error
- func (op *Operations) GroupBy(groupBy string) DBOperations
- func (op *Operations) Having(conditions *Conditions) DBOperations
- func (op *Operations) Joins(query string, args ...any) DBOperations
- func (op *Operations) NewSession() DBOperations
- func (op *Operations) Or(conditions *Conditions) DBOperations
- func (op *Operations) OrderBy(orderBy string) DBOperations
- func (op *Operations) Paging(pageNo int, pageSize int) DBOperations
- func (op *Operations) Raw(sql string, values ...any) DBOperations
- func (op *Operations) Row() (*TableRow, error)
- func (op *Operations) Rows(pageNo int, pageSize int) ([]TableRow, error)
- func (op *Operations) Select(query string, args ...any) DBOperations
- func (op *Operations) Table(name string, args ...any) DBOperations
- func (op *Operations) Updates(newTableRow *TableRow) error
- func (op *Operations) UpdatesWithRowsAffected(newTableRow *TableRow) (int64, error)
- func (op *Operations) Where(conditions *Conditions) DBOperations
- type Table
- type TableColumn
- type TableRow
- func (tableRow *TableRow) AddColumnValueBool(columnName string, value bool) *TableRow
- func (tableRow *TableRow) AddColumnValueBoolPtr(columnName string, value *bool) *TableRow
- func (tableRow *TableRow) AddColumnValueBytes(columnName string, value []byte) *TableRow
- func (tableRow *TableRow) AddColumnValueBytesPtr(columnName string, value *[]byte) *TableRow
- func (tableRow *TableRow) AddColumnValueFloat32(columnName string, value float32) *TableRow
- func (tableRow *TableRow) AddColumnValueFloat32Ptr(columnName string, value *float32) *TableRow
- func (tableRow *TableRow) AddColumnValueFloat64(columnName string, value float64) *TableRow
- func (tableRow *TableRow) AddColumnValueFloat64Ptr(columnName string, value *float64) *TableRow
- func (tableRow *TableRow) AddColumnValueInt(columnName string, value int) *TableRow
- func (tableRow *TableRow) AddColumnValueInt16(columnName string, value int16) *TableRow
- func (tableRow *TableRow) AddColumnValueInt16Ptr(columnName string, value *int16) *TableRow
- func (tableRow *TableRow) AddColumnValueInt32(columnName string, value int32) *TableRow
- func (tableRow *TableRow) AddColumnValueInt32Ptr(columnName string, value *int32) *TableRow
- func (tableRow *TableRow) AddColumnValueInt64(columnName string, value int64) *TableRow
- func (tableRow *TableRow) AddColumnValueInt64Ptr(columnName string, value *int64) *TableRow
- func (tableRow *TableRow) AddColumnValueInt8(columnName string, value int8) *TableRow
- func (tableRow *TableRow) AddColumnValueInt8Ptr(columnName string, value *int8) *TableRow
- func (tableRow *TableRow) AddColumnValueIntPtr(columnName string, value *int) *TableRow
- func (tableRow *TableRow) AddColumnValueString(columnName string, value string) *TableRow
- func (tableRow *TableRow) AddColumnValueStringPtr(columnName string, value *string) *TableRow
- func (tableRow *TableRow) AddColumnValueTime(columnName string, value time.Time) *TableRow
- func (tableRow *TableRow) AddColumnValueTimePtr(columnName string, value *time.Time) *TableRow
- func (tableRow *TableRow) AddColumnValueUint(columnName string, value uint) *TableRow
- func (tableRow *TableRow) AddColumnValueUint16(columnName string, value uint16) *TableRow
- func (tableRow *TableRow) AddColumnValueUint16Ptr(columnName string, value *uint16) *TableRow
- func (tableRow *TableRow) AddColumnValueUint32(columnName string, value uint32) *TableRow
- func (tableRow *TableRow) AddColumnValueUint32Ptr(columnName string, value *uint32) *TableRow
- func (tableRow *TableRow) AddColumnValueUint64(columnName string, value uint64) *TableRow
- func (tableRow *TableRow) AddColumnValueUint64Ptr(columnName string, value *uint64) *TableRow
- func (tableRow *TableRow) AddColumnValueUint8(columnName string, value uint8) *TableRow
- func (tableRow *TableRow) AddColumnValueUint8Ptr(columnName string, value *uint8) *TableRow
- func (tableRow *TableRow) AddColumnValueUintPtr(columnName string, value *uint) *TableRow
- func (tableRow *TableRow) ColumnValueBool(columnName string) bool
- func (tableRow *TableRow) ColumnValueBoolPtr(columnName string) *bool
- func (tableRow *TableRow) ColumnValueBytes(columnName string) []byte
- func (tableRow *TableRow) ColumnValueBytesPtr(columnName string) *[]byte
- func (tableRow *TableRow) ColumnValueFloat32(columnName string) float32
- func (tableRow *TableRow) ColumnValueFloat32Ptr(columnName string) *float32
- func (tableRow *TableRow) ColumnValueFloat64(columnName string) float64
- func (tableRow *TableRow) ColumnValueFloat64Ptr(columnName string) *float64
- func (tableRow *TableRow) ColumnValueInt(columnName string) int
- func (tableRow *TableRow) ColumnValueInt16(columnName string) int16
- func (tableRow *TableRow) ColumnValueInt16Ptr(columnName string) *int16
- func (tableRow *TableRow) ColumnValueInt32(columnName string) int32
- func (tableRow *TableRow) ColumnValueInt32Ptr(columnName string) *int32
- func (tableRow *TableRow) ColumnValueInt64(columnName string) int64
- func (tableRow *TableRow) ColumnValueInt64Ptr(columnName string) *int64
- func (tableRow *TableRow) ColumnValueInt8(columnName string) int8
- func (tableRow *TableRow) ColumnValueInt8Ptr(columnName string) *int8
- func (tableRow *TableRow) ColumnValueIntPtr(columnName string) *int
- func (tableRow *TableRow) ColumnValueString(columnName string) string
- func (tableRow *TableRow) ColumnValueStringPtr(columnName string) *string
- func (tableRow *TableRow) ColumnValueTime(columnName string) time.Time
- func (tableRow *TableRow) ColumnValueTimePtr(columnName string) *time.Time
- func (tableRow *TableRow) ColumnValueUint(columnName string) uint
- func (tableRow *TableRow) ColumnValueUint16(columnName string) uint16
- func (tableRow *TableRow) ColumnValueUint16Ptr(columnName string) *uint16
- func (tableRow *TableRow) ColumnValueUint32(columnName string) uint32
- func (tableRow *TableRow) ColumnValueUint32Ptr(columnName string) *uint32
- func (tableRow *TableRow) ColumnValueUint64(columnName string) uint64
- func (tableRow *TableRow) ColumnValueUint64Ptr(columnName string) *uint64
- func (tableRow *TableRow) ColumnValueUint8(columnName string) uint8
- func (tableRow *TableRow) ColumnValueUint8Ptr(columnName string) *uint8
- func (tableRow *TableRow) ColumnValueUintPtr(columnName string) *uint
- func (tableRow *TableRow) Empty() bool
- func (tableRow *TableRow) Len() int
- func (tableRow *TableRow) ToMap() map[string]any
- type TransactionDBOperations
- type TransactionOperations
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrDBRecordHasExist = errors.New("记录已存在") ErrDBRecordNotExist = errors.New("记录不存在") )
Functions ¶
func DestroyOperation ¶
func DestroyOperation(op *Operations) error
Types ¶
type BaseDBOperations ¶
type BaseDBOperations interface { // AutoMigrate 创建表 AutoMigrate(tables ...Table) error // 会重置数据库连接的方法 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() (int64, error) CheckExist() (bool, error) CheckHasOnlyOne() (bool, error) }
type Conditions ¶
type Conditions struct {
// contains filtered or unexported fields
}
func NewConditions ¶
func NewConditions() *Conditions
func (*Conditions) Equal ¶
func (clause *Conditions) Equal(columnName string, value any) *Conditions
func (*Conditions) GreaterThan ¶
func (clause *Conditions) GreaterThan(columnName string, value any) *Conditions
func (*Conditions) GreaterThanAndEqual ¶
func (clause *Conditions) GreaterThanAndEqual(columnName string, value any) *Conditions
func (*Conditions) In ¶
func (clause *Conditions) In(columnName string, value any) *Conditions
func (*Conditions) LessThan ¶
func (clause *Conditions) LessThan(columnName string, value any) *Conditions
func (*Conditions) LessThanAndEqual ¶
func (clause *Conditions) LessThanAndEqual(columnName string, value any) *Conditions
func (*Conditions) Like ¶
func (clause *Conditions) Like(columnName string, value any) *Conditions
func (*Conditions) Not ¶
func (clause *Conditions) Not(columnName string, value any) *Conditions
func (*Conditions) NotIn ¶
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 ¶
type Operations ¶
type Operations struct {
// contains filtered or unexported fields
}
func NewOperations ¶
func NewOperations(dbConfig *DBConfig) (*Operations, error)
func (*Operations) AutoMigrate ¶ added in v0.1.2
func (op *Operations) AutoMigrate(tables ...Table) error
func (*Operations) BeginTransaction ¶
func (op *Operations) BeginTransaction() TransactionDBOperations
func (*Operations) CheckExist ¶
func (op *Operations) CheckExist() (bool, error)
func (*Operations) CheckHasOnlyOne ¶
func (op *Operations) CheckHasOnlyOne() (bool, error)
func (*Operations) Count ¶
func (op *Operations) Count() (int64, error)
func (*Operations) Create ¶
func (op *Operations) Create(tableRow *TableRow) error
func (*Operations) CreateBatch ¶
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) 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 Table ¶ added in v0.1.2
type Table struct { TableName string Columns []TableColumn }
type TableColumn ¶ added in v0.1.2
type TableColumn struct { Name string Type string Comment string PrimaryKey bool Size int Unique bool NotNull bool Index bool UniqueIndex string Default any }
func (*TableColumn) ToDBModelField ¶ added in v0.1.2
func (column *TableColumn) ToDBModelField() (*reflect.StructField, error)
type TableRow ¶
type TableRow struct {
// contains filtered or unexported fields
}
func NewTableRow ¶
func NewTableRow() *TableRow
func NewTableRowFromMap ¶
func (*TableRow) AddColumnValueBool ¶
func (*TableRow) AddColumnValueBoolPtr ¶ added in v0.1.7
func (*TableRow) AddColumnValueBytes ¶
func (*TableRow) AddColumnValueBytesPtr ¶ added in v0.1.7
func (*TableRow) AddColumnValueFloat32 ¶
func (*TableRow) AddColumnValueFloat32Ptr ¶ added in v0.1.7
func (*TableRow) AddColumnValueFloat64 ¶
func (*TableRow) AddColumnValueFloat64Ptr ¶ added in v0.1.7
func (*TableRow) AddColumnValueInt ¶
func (*TableRow) AddColumnValueInt16 ¶
func (*TableRow) AddColumnValueInt16Ptr ¶ added in v0.1.7
func (*TableRow) AddColumnValueInt32 ¶
func (*TableRow) AddColumnValueInt32Ptr ¶ added in v0.1.7
func (*TableRow) AddColumnValueInt64 ¶
func (*TableRow) AddColumnValueInt64Ptr ¶ added in v0.1.7
func (*TableRow) AddColumnValueInt8 ¶
func (*TableRow) AddColumnValueInt8Ptr ¶ added in v0.1.7
func (*TableRow) AddColumnValueIntPtr ¶ added in v0.1.7
func (*TableRow) AddColumnValueString ¶
func (*TableRow) AddColumnValueStringPtr ¶ added in v0.1.7
func (*TableRow) AddColumnValueTime ¶
func (*TableRow) AddColumnValueTimePtr ¶ added in v0.1.7
func (*TableRow) AddColumnValueUint ¶
func (*TableRow) AddColumnValueUint16 ¶
func (*TableRow) AddColumnValueUint16Ptr ¶ added in v0.1.7
func (*TableRow) AddColumnValueUint32 ¶
func (*TableRow) AddColumnValueUint32Ptr ¶ added in v0.1.7
func (*TableRow) AddColumnValueUint64 ¶
func (*TableRow) AddColumnValueUint64Ptr ¶ added in v0.1.7
func (*TableRow) AddColumnValueUint8 ¶
func (*TableRow) AddColumnValueUint8Ptr ¶ added in v0.1.7
func (*TableRow) AddColumnValueUintPtr ¶ added in v0.1.7
func (*TableRow) ColumnValueBool ¶
func (*TableRow) ColumnValueBoolPtr ¶ added in v0.1.7
func (*TableRow) ColumnValueBytes ¶
func (*TableRow) ColumnValueBytesPtr ¶ added in v0.1.7
func (*TableRow) ColumnValueFloat32 ¶
func (*TableRow) ColumnValueFloat32Ptr ¶ added in v0.1.7
func (*TableRow) ColumnValueFloat64 ¶
func (*TableRow) ColumnValueFloat64Ptr ¶ added in v0.1.7
func (*TableRow) ColumnValueInt ¶
func (*TableRow) ColumnValueInt16 ¶
func (*TableRow) ColumnValueInt16Ptr ¶ added in v0.1.7
func (*TableRow) ColumnValueInt32 ¶
func (*TableRow) ColumnValueInt32Ptr ¶ added in v0.1.7
func (*TableRow) ColumnValueInt64 ¶
func (*TableRow) ColumnValueInt64Ptr ¶ added in v0.1.7
func (*TableRow) ColumnValueInt8 ¶
func (*TableRow) ColumnValueInt8Ptr ¶ added in v0.1.7
func (*TableRow) ColumnValueIntPtr ¶ added in v0.1.7
func (*TableRow) ColumnValueString ¶
func (*TableRow) ColumnValueStringPtr ¶ added in v0.1.7
func (*TableRow) ColumnValueTime ¶
func (*TableRow) ColumnValueTimePtr ¶ added in v0.1.7
func (*TableRow) ColumnValueUint ¶
func (*TableRow) ColumnValueUint16 ¶
func (*TableRow) ColumnValueUint16Ptr ¶ added in v0.1.7
func (*TableRow) ColumnValueUint32 ¶
func (*TableRow) ColumnValueUint32Ptr ¶ added in v0.1.7
func (*TableRow) ColumnValueUint64 ¶
func (*TableRow) ColumnValueUint64Ptr ¶ added in v0.1.7
func (*TableRow) ColumnValueUint8 ¶
func (*TableRow) ColumnValueUint8Ptr ¶ added in v0.1.7
func (*TableRow) ColumnValueUintPtr ¶ added in v0.1.7
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()
Click to show internal directories.
Click to hide internal directories.