mysqlMng

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseInterface

type BaseInterface interface {
	GetError() error
	GetRowsAffected() int64
	SetError(error)
	SetRowsAffected(int64)
}

type BaseStruct

type BaseStruct struct {
	Error        error
	RowsAffected int64
}

type Delete

type Delete struct {
	BaseStruct
	Condition  map[string]interface{}
	Row        interface{}
	RawJsonMap map[string]interface{}
}

删除操作的基本结构体

func (*Delete) GetCondition

func (delete *Delete) GetCondition() map[string]interface{}

func (*Delete) GetError

func (delete *Delete) GetError() error

func (*Delete) GetRawJsonMap

func (delete *Delete) GetRawJsonMap() map[string]interface{}

func (*Delete) GetRow

func (delete *Delete) GetRow() interface{}

func (*Delete) GetRowsAffected

func (delete *Delete) GetRowsAffected() int64

func (*Delete) SetCondition

func (delete *Delete) SetCondition(condition map[string]interface{})

func (*Delete) SetError

func (delete *Delete) SetError(err error)

func (*Delete) SetRawJsonMap

func (delete *Delete) SetRawJsonMap(rawJsonMap map[string]interface{})

func (*Delete) SetRow

func (delete *Delete) SetRow(row interface{})

func (*Delete) SetRowsAffected

func (delete *Delete) SetRowsAffected(rowsAffected int64)

type DeleteInterface

type DeleteInterface interface {
	JsonInterface
	BaseInterface
	// Getter
	GetCondition() map[string]interface{}
	GetRow() interface{}
	//Setter
	SetCondition(map[string]interface{})
	SetRow(interface{})
}

删除接口

type IDInterface

type IDInterface interface {
	GetID() int
}

结构化方法种用来获取新插入记录的ID值

type Insert

type Insert struct {
	BaseStruct
	NewID      int // 没有实际意义,无法实现,只为了区分interface
	Row        interface{}
	RawJsonMap map[string]interface{}
}

插入操作的基本结构体

func (*Insert) GetError

func (insert *Insert) GetError() error

func (*Insert) GetNewID

func (insert *Insert) GetNewID() int

func (*Insert) GetRawJsonMap

func (insert *Insert) GetRawJsonMap() map[string]interface{}

func (*Insert) GetRow

func (insert *Insert) GetRow() interface{}

func (*Insert) GetRowsAffected

func (insert *Insert) GetRowsAffected() int64

func (*Insert) SetError

func (insert *Insert) SetError(err error)

func (*Insert) SetNewID

func (insert *Insert) SetNewID(newID int)

func (*Insert) SetRawJsonMap

func (insert *Insert) SetRawJsonMap(rawJsonMap map[string]interface{})

func (*Insert) SetRow

func (insert *Insert) SetRow(row interface{})

func (*Insert) SetRowsAffected

func (insert *Insert) SetRowsAffected(rowsAffected int64)

type InsertInterface

type InsertInterface interface {
	JsonInterface
	BaseInterface
	// Getter
	GetRow() interface{}
	GetNewID() int
	//Setter
	SetRow(interface{})
	SetNewID(int)
}

插入接口

type JsonInterface

type JsonInterface interface {
	// Getter
	GetRawJsonMap() map[string]interface{}
	//Setter
	SetRawJsonMap(map[string]interface{})
}

涉及到json操作的接口

type MysqlMng

type MysqlMng struct {
	Conn      *gorm.DB // 普通会话
	TransConn *gorm.DB // 事务会话
}

func NewMysqlMng

func NewMysqlMng() *MysqlMng

*

  • @func: NewMysqlMng mysql管理器工厂模式
  • @author: Wiidz
  • @date: 2020-04-15

func (*MysqlMng) Commit

func (mysqlMng *MysqlMng) Commit()

提交事务

func (*MysqlMng) IsExist

func (mysqlMng *MysqlMng) IsExist(condition map[string]interface{}, tableName string) (err error)

复合condition成为cons、vals的结构

func (*MysqlMng) IsNotFound

func (mysqlMng *MysqlMng) IsNotFound(err error) bool

判断读取结果是否为空错误

func (*MysqlMng) NewCommonConn

func (mysqlMng *MysqlMng) NewCommonConn()

获取一个新的会话

func (*MysqlMng) NewTransConn

func (mysqlMng *MysqlMng) NewTransConn()

开启一个事务会话

func (*MysqlMng) Rollback

func (mysqlMng *MysqlMng) Rollback()

回滚事务

func (*MysqlMng) WhereBuild

func (mysqlMng *MysqlMng) WhereBuild(condition map[string]interface{}) (whereSQL string, vals []interface{}, err error)

复合condition成为cons、vals的结构

func (*MysqlMng) WhereOrBuild

func (mysqlMng *MysqlMng) WhereOrBuild(condition map[string]interface{}) (whereSQL string, vals []interface{}, err error)

复合condition成为cons、vals的结构

type NullType

type NullType byte

用于判断是否是null值

const (
	IsNull    NullType // IsNull the same as `is null`
	IsNotNull          // IsNotNull the same as `is not null`
)

type OnlyID

type OnlyID struct {
	ID int `gorm:"primary_key;column:id;type:int(11);not null" json:"id"` // 编号
}

简单方法种用来获取新插入记录的ID值

type Read

type Read struct {
	BaseStruct
	Condition map[string]interface{}
	PageNow   int    `json:"page_now" belong:"etc" default:"1"`
	PageSize  int    `json:"page_size" belong:"etc" default:"10"`
	Order     string `json:"order" belong:"etc" default:"ids asc"`
	Single    bool
	Preloads  []string
	Rows      interface{}
	Count     int64
}

读取操作的基本结构体

func (*Read) GetCondition

func (read *Read) GetCondition() map[string]interface{}

func (*Read) GetCount

func (read *Read) GetCount() int64

func (*Read) GetError

func (read *Read) GetError() error

func (*Read) GetLimit

func (read *Read) GetLimit() int

func (*Read) GetOffset

func (read *Read) GetOffset() int

func (*Read) GetOrder

func (read *Read) GetOrder() string

func (*Read) GetPageNow

func (read *Read) GetPageNow() int

func (*Read) GetPageSize

func (read *Read) GetPageSize() int

func (*Read) GetPreloads

func (read *Read) GetPreloads() []string

func (*Read) GetRows

func (read *Read) GetRows() interface{}

func (*Read) GetRowsAffected

func (read *Read) GetRowsAffected() int64

func (*Read) SetCondition

func (read *Read) SetCondition(condition map[string]interface{})

func (*Read) SetCount

func (read *Read) SetCount(count int64)

func (*Read) SetError

func (read *Read) SetError(err error)

func (*Read) SetOrder

func (read *Read) SetOrder(order string)

func (*Read) SetPageNow

func (read *Read) SetPageNow(pageNow int)

func (*Read) SetPageSize

func (read *Read) SetPageSize(pageSize int)

func (*Read) SetRows

func (read *Read) SetRows(rows interface{})

func (*Read) SetRowsAffected

func (read *Read) SetRowsAffected(rowsAffected int64)

type ReadInterface

type ReadInterface interface {
	BaseInterface
	// Getter
	GetPreloads() []string
	GetCondition() map[string]interface{}
	GetOrder() string
	GetOffset() int
	GetPageSize() int
	GetPageNow() int
	GetRows() interface{}
	GetCount() int64
	GetLimit() int
	//Setter
	SetRows(interface{})
	SetCount(int64)
	SetCondition(map[string]interface{})
	SetOrder(string)
	SetPageNow(int)
	SetPageSize(int)
}

读接口

type Update

type Update struct {
	BaseStruct
	TableName  string
	Condition  map[string]interface{}
	Value      map[string]interface{}
	RawJsonMap map[string]interface{}
}

修改操作的基本结构体

func (*Update) GetCondition

func (update *Update) GetCondition() map[string]interface{}

func (*Update) GetError

func (update *Update) GetError() error

func (*Update) GetRawJsonMap

func (update *Update) GetRawJsonMap() map[string]interface{}

func (*Update) GetRowsAffected

func (update *Update) GetRowsAffected() int64

func (*Update) GetTableName

func (update *Update) GetTableName() string

func (*Update) GetValue

func (update *Update) GetValue() map[string]interface{}

func (*Update) SetCondition

func (update *Update) SetCondition(condition map[string]interface{})

func (*Update) SetError

func (update *Update) SetError(err error)

func (*Update) SetRawJsonMap

func (update *Update) SetRawJsonMap(rawJsonMap map[string]interface{})

func (*Update) SetRowsAffected

func (update *Update) SetRowsAffected(rowsAffected int64)

func (*Update) SetTableName

func (update *Update) SetTableName(tableName string)

func (*Update) SetValue

func (update *Update) SetValue(value map[string]interface{})

type UpdateInterface

type UpdateInterface interface {
	JsonInterface
	BaseInterface
	// Getter
	GetTableName() string
	GetCondition() map[string]interface{}
	GetValue() map[string]interface{}
	//Setter
	SetTableName(string)
	SetCondition(map[string]interface{})
	SetValue(map[string]interface{})
}

修改接口

Jump to

Keyboard shortcuts

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