Documentation ¶
Index ¶
- func GenModelAndEntity(moduleName string, dbConfig SlaveDB, isCode bool)
- func GenModelAndEntityByTableName(moduleName, table string, dbConfig SlaveDB, isCode bool)
- func InjectCreatePool(fun CreateConnectFunc)
- func TransSql(sql string, whereParams ...interface{}) string
- type Aliaser
- type CreateConnectFunc
- type DB
- func (db *DB) BeginTransaction()
- func (db *DB) Commit()
- func (db *DB) Desc(tableName string) lib.Columns
- func (db *DB) Exec(sql string) int64
- func (db *DB) IsExist(tableName string) bool
- func (db *DB) Query(sql string, whereParams ...interface{}) lib.SqlRows
- func (db *DB) Rollback()
- func (db *DB) SetDB(connectName, databaseName string) DBer
- func (db *DB) SetPool(pool MysqlPooler) DBPool
- func (db *DB) ShowTables() []string
- type DBConfig
- type DBPool
- type DBer
- type Fielder
- type GroupByer
- type Havinger
- type Joiner
- type Limiter
- type Model
- func (m *Model) Alias(name string) Aliaser
- func (m *Model) AndHaving(field string, value interface{}) Havinger
- func (m *Model) AndHavingIn(field string, value interface{}) Havinger
- func (m *Model) AndHavingNotIn(field string, value interface{}) Havinger
- func (m *Model) AndHavingRaw(having string) Havinger
- func (m *Model) AndHavingSymbol(field, symbol string, value interface{}) Havinger
- func (m *Model) AndOn(field string, value interface{}) Oner
- func (m *Model) AndOnIn(field string, value interface{}) Oner
- func (m *Model) AndOnNotIn(field string, value interface{}) Oner
- func (m *Model) AndOnRaw(on string) Oner
- func (m *Model) AndOnSymbol(field, symbol string, value interface{}) Oner
- func (m *Model) AndWhere(field string, value interface{}) Wherer
- func (m *Model) AndWhereIn(field string, value interface{}) Wherer
- func (m *Model) AndWhereNotIn(field string, value interface{}) Wherer
- func (m *Model) AndWhereRaw(where string) Wherer
- func (m *Model) AndWhereSymbol(field, symbol string, value interface{}) Wherer
- func (m *Model) Count() int64
- func (m *Model) CountByClear(isClear bool) int64
- func (m *Model) Create(row lib.SqlIn) int64
- func (m *Model) DB() DBer
- func (m *Model) Delete() int64
- func (m *Model) Drop() int64
- func (m *Model) Fields(fields ...string) Fielder
- func (m *Model) Find() lib.SqlRow
- func (m *Model) Get() lib.SqlRows
- func (m *Model) GetByClear(isClear bool) lib.SqlRows
- func (m *Model) GetLastSql() string
- func (m *Model) GetModelSql() (string, []interface{})
- func (m *Model) GetSqlInfo() (string, []interface{})
- func (m *Model) GroupBy(field ...string) GroupByer
- func (m *Model) Having(field string, value interface{}) Havinger
- func (m *Model) HavingIn(field string, value interface{}) Havinger
- func (m *Model) HavingNotIn(field string, value interface{}) Havinger
- func (m *Model) HavingRaw(having string) Havinger
- func (m *Model) HavingSymbol(field, symbol string, value interface{}) Havinger
- func (m *Model) Init(dbName, tableName string) Modeler
- func (m *Model) InitByConnectName(connectName, dbName, tableName string) Modeler
- func (m *Model) Insert(row lib.SqlIn) int64
- func (m *Model) InsertOnDuplicate(row lib.SqlIn, updateRow lib.SqlIn) int64
- func (m *Model) Join(tableName string) Joiner
- func (m *Model) LeftJoin(tableName string) Joiner
- func (m *Model) Limit(offset, count int) Limiter
- func (m *Model) On(field string, value interface{}) Oner
- func (m *Model) OnIn(field string, value interface{}) Oner
- func (m *Model) OnNotIn(field string, value interface{}) Oner
- func (m *Model) OnRaw(on string) Oner
- func (m *Model) OnSymbol(field, symbol string, value interface{}) Oner
- func (m *Model) Optimize() int64
- func (m *Model) OrHaving(field string, value interface{}) Havinger
- func (m *Model) OrHavingIn(field string, value interface{}) Havinger
- func (m *Model) OrHavingNotIn(field string, value interface{}) Havinger
- func (m *Model) OrHavingRaw(having string) Havinger
- func (m *Model) OrHavingSymbol(field, symbol string, value interface{}) Havinger
- func (m *Model) OrOn(field string, value interface{}) Oner
- func (m *Model) OrOnIn(field string, value interface{}) Oner
- func (m *Model) OrOnNotIn(field string, value interface{}) Oner
- func (m *Model) OrOnRaw(on string) Oner
- func (m *Model) OrOnSymbol(field, symbol string, value interface{}) Oner
- func (m *Model) OrWhere(field string, value interface{}) Wherer
- func (m *Model) OrWhereIn(field string, value interface{}) Wherer
- func (m *Model) OrWhereNotIn(field string, value interface{}) Wherer
- func (m *Model) OrWhereRaw(where string) Wherer
- func (m *Model) OrWhereSymbol(field, symbol string, value interface{}) Wherer
- func (m *Model) OrderBy(orderBy string) OrderByer
- func (m *Model) Pager(page, pageSize int) (lib.SqlRows, lib.SqlRow)
- func (m *Model) Replace(row lib.SqlIn) int64
- func (m *Model) RightJoin(tableName string) Joiner
- func (m *Model) SoftDel() int64
- func (m *Model) Truncate() int64
- func (m *Model) Union(model Modeler) Unioner
- func (m *Model) Update(data lib.SqlIn) int64
- func (m *Model) Where(field string, value interface{}) Wherer
- func (m *Model) WhereIn(field string, value interface{}) Wherer
- func (m *Model) WhereNotIn(field string, value interface{}) Wherer
- func (m *Model) WhereRaw(where string) Wherer
- func (m *Model) WhereSymbol(field, symbol string, value interface{}) Wherer
- type Modeler
- type MysqlConnect
- type MysqlPool
- func (m *MysqlPool) AddConnect(connect MysqlConnect)
- func (m *MysqlPool) AddConnects(connects []MysqlConnect)
- func (m *MysqlPool) BeginTx(connectName string)
- func (m *MysqlPool) Close()
- func (m *MysqlPool) EndTx(connectName string)
- func (m *MysqlPool) GetDB(connectName string) *sql.DB
- func (m *MysqlPool) GetIncludeReadDB(connectName string) *sql.DB
- func (m *MysqlPool) GetTx(connectName string) *sql.Tx
- func (m *MysqlPool) Init(connects []MysqlConnect)
- func (m *MysqlPool) IsTransaction(connectName string) bool
- func (m *MysqlPool) SetTx(connectName string, tx *sql.Tx)
- type MysqlPooler
- type Oner
- type OrderByer
- type SlaveDB
- type Table
- func (t *Table) Delete(onParams []interface{}, where string, whereParams ...interface{}) int64
- func (t *Table) Drop() int64
- func (t *Table) GetDB() *DB
- func (t *Table) GetLastSql() string
- func (t *Table) GetSqlInfo() (string, []interface{})
- func (t *Table) Insert(row lib.SqlIn) int64
- func (t *Table) InsertOnDuplicate(row lib.SqlIn, updateRow lib.SqlIn) int64
- func (t *Table) Optimize() int64
- func (t *Table) Replace(row lib.SqlIn) int64
- func (t *Table) Select(fields string, where string, whereParams ...interface{}) lib.SqlRows
- func (t *Table) SelectByHasWhere(fields string, where string, hasWhere bool, whereParams ...interface{}) lib.SqlRows
- func (t *Table) SetDB(db *DB)
- func (t *Table) Truncate() int64
- func (t *Table) Update(row lib.SqlIn, onParams []interface{}, where string, ...) int64
- type Tabler
- type Unioner
- type Wherer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenModelAndEntity ¶
GenModelAndEntity 自动生成Model和Entity
func GenModelAndEntityByTableName ¶
GenModelAndEntity 自动生成Model和Entity
func InjectCreatePool ¶
func InjectCreatePool(fun CreateConnectFunc)
InjectCreatePool 注入连接池的创建过程 connect 连接mysql配置 fun 回调函数返回mysql连接配置
Types ¶
type Aliaser ¶
type Aliaser interface { Join(tableName string) Joiner LeftJoin(tableName string) Joiner RightJoin(tableName string) Joiner Union(model Modeler) Unioner Where(field string, value interface{}) Wherer WhereRaw(where string) Wherer WhereSymbol(field, symbol string, value interface{}) Wherer WhereIn(field string, value interface{}) Wherer WhereNotIn(field string, value interface{}) Wherer GroupBy(field ...string) GroupByer Count() int64 Get() lib.SqlRows Find() lib.SqlRow OrderBy(orderBy string) OrderByer Limit(offset, count int) Limiter Pager(page, pageSize int) (lib.SqlRows, lib.SqlRow) Update(data lib.SqlIn) int64 }
Aliaser 另外取名接口
type DBer ¶
type DBer interface { BeginTransaction() Commit() Rollback() Exec(sql string) int64 Query(sql string, whereParams ...interface{}) lib.SqlRows Desc(tableName string) lib.Columns IsExist(tableName string) bool ShowTables() []string }
DBer 数据库接口
type Fielder ¶
type Fielder interface { Alias(name string) Aliaser Join(tableName string) Joiner LeftJoin(tableName string) Joiner RightJoin(tableName string) Joiner Union(model Modeler) Unioner Where(field string, value interface{}) Wherer WhereRaw(where string) Wherer WhereSymbol(field, symbol string, value interface{}) Wherer WhereIn(field string, value interface{}) Wherer WhereNotIn(field string, value interface{}) Wherer GroupBy(field ...string) GroupByer Count() int64 Get() lib.SqlRows Find() lib.SqlRow OrderBy(orderBy string) OrderByer Limit(offset, count int) Limiter Pager(page, pageSize int) (lib.SqlRows, lib.SqlRow) }
Fielder 字段暴露出去的接口
type GroupByer ¶
type GroupByer interface { Having(field string, value interface{}) Havinger HavingRaw(having string) Havinger HavingSymbol(field, symbol string, value interface{}) Havinger HavingIn(field string, value interface{}) Havinger HavingNotIn(field string, value interface{}) Havinger Get() lib.SqlRows Find() lib.SqlRow Count() int64 OrderBy(orderBy string) OrderByer Limit(offset, count int) Limiter Union(model Modeler) Unioner Pager(page, pageSize int) (lib.SqlRows, lib.SqlRow) }
GroupByer 分组接口
type Havinger ¶
type Havinger interface { AndHaving(field string, value interface{}) Havinger AndHavingRaw(having string) Havinger AndHavingSymbol(field, symbol string, value interface{}) Havinger AndHavingIn(field string, value interface{}) Havinger AndHavingNotIn(field string, value interface{}) Havinger OrHaving(field string, value interface{}) Havinger OrHavingRaw(having string) Havinger OrHavingSymbol(field, symbol string, value interface{}) Havinger OrHavingIn(field string, value interface{}) Havinger OrHavingNotIn(field string, value interface{}) Havinger Get() lib.SqlRows Find() lib.SqlRow Count() int64 OrderBy(orderBy string) OrderByer Limit(offset, count int) Limiter Union(model Modeler) Unioner Pager(page, pageSize int) (lib.SqlRows, lib.SqlRow) }
Havinger having条件
type Joiner ¶
type Joiner interface { On(field string, value interface{}) Oner OnRaw(on string) Oner OnSymbol(field, symbol string, value interface{}) Oner OnIn(field string, value interface{}) Oner OnNotIn(field string, value interface{}) Oner }
Joiner 连接接口
type Model ¶
Model 模型
func (*Model) AndHavingIn ¶
AndHavingIn having条件
func (*Model) AndHavingNotIn ¶
AndHavingNotIn having条件
func (*Model) AndHavingRaw ¶
AndHavingRaw having条件
func (*Model) AndHavingSymbol ¶
AndHavingSymbol having条件
func (*Model) AndOnNotIn ¶
AndOnNotIn Join 条件on
func (*Model) AndOnSymbol ¶
AndOnSymbol Join 条件on
func (*Model) AndWhereIn ¶
AndWhereIn where条件
func (*Model) AndWhereNotIn ¶
AndWhereNotIn where条件
func (*Model) AndWhereSymbol ¶
AndWhereSymbol where条件
func (*Model) GetSqlInfo ¶
GetSqlInfo 获得最后执行的sql
func (*Model) HavingNotIn ¶
HavingNotIn having条件
func (*Model) HavingSymbol ¶
HavingSymbol having条件
func (*Model) InitByConnectName ¶
Init 初始化
func (*Model) InsertOnDuplicate ¶
InsertOnDuplicate 如果你插入的记录导致一个UNIQUE索引或者primary key(主键)出现重复,那么就会认为该条记录存在,则执行update语句而不是insert语句,反之,则执行insert语句而不是更新语句。
func (*Model) OrHavingIn ¶
OrHavingIn having条件
func (*Model) OrHavingNotIn ¶
OrHavingNotIn having条件
func (*Model) OrHavingRaw ¶
OrHavingRaw having条件
func (*Model) OrHavingSymbol ¶
OrHavingSymbol having条件
func (*Model) OrOnSymbol ¶
OrOnSymbol Join 条件on
func (*Model) OrWhereNotIn ¶
OrWhereNotIn where条件
func (*Model) OrWhereSymbol ¶
OrWhereSymbol where条件
func (*Model) WhereNotIn ¶
WhereNotIn where条件
func (*Model) WhereSymbol ¶
WhereSymbol where条件
type Modeler ¶
type Modeler interface { Fields(fields ...string) Fielder Count() int64 GetLastSql() string GetSqlInfo() (string, []interface{}) GetModelSql() (string, []interface{}) Alias(name string) Aliaser Join(tableName string) Joiner LeftJoin(tableName string) Joiner RightJoin(tableName string) Joiner Union(model Modeler) Unioner Where(field string, value interface{}) Wherer WhereRaw(where string) Wherer WhereSymbol(field, symbol string, value interface{}) Wherer WhereIn(field string, value interface{}) Wherer WhereNotIn(field string, value interface{}) Wherer GroupBy(field ...string) GroupByer Get() lib.SqlRows Find() lib.SqlRow OrderBy(orderBy string) OrderByer Limit(offset, count int) Limiter Pager(page, pageSize int) (lib.SqlRows, lib.SqlRow) Update(data lib.SqlIn) int64 Insert(row lib.SqlIn) int64 Create(row lib.SqlIn) int64 Replace(row lib.SqlIn) int64 InsertOnDuplicate(row lib.SqlIn, updateRow lib.SqlIn) int64 Drop() int64 Truncate() int64 Optimize() int64 Delete() int64 SoftDel() int64 DB() DBer }
Modeler 模型接口
func NewModelByConnectName ¶
NewModelByConnectName 新建一个模型
type MysqlConnect ¶
MysqlConnect mysql连接配置数据
func (MysqlConnect) String ¶
func (m MysqlConnect) String() string
type MysqlPool ¶
type MysqlPool struct {
// contains filtered or unexported fields
}
MysqlPool 全局连接池
func (*MysqlPool) AddConnects ¶
func (m *MysqlPool) AddConnects(connects []MysqlConnect)
AddConnects 添加多个连接
func (*MysqlPool) GetIncludeReadDB ¶
GetIncludeReadDB 取出只读数据库连接
func (*MysqlPool) IsTransaction ¶
IsTransaction 是否开启事务
type MysqlPooler ¶
type MysqlPooler interface { GetDB(connectName string) *sql.DB GetIncludeReadDB(connectName string) *sql.DB SetTx(connectName string, tx *sql.Tx) GetTx(connectName string) *sql.Tx BeginTx(connectName string) EndTx(connectName string) IsTransaction(connectName string) bool Close() Init(connect []MysqlConnect) AddConnect(connect MysqlConnect) AddConnects(connects []MysqlConnect) }
MysqlPooler 全局连接池接口
type Oner ¶
type Oner interface { OrOn(field string, value interface{}) Oner OrOnRaw(on string) Oner OrOnSymbol(field, symbol string, value interface{}) Oner OrOnIn(field string, value interface{}) Oner OrOnNotIn(field string, value interface{}) Oner AndOn(field string, value interface{}) Oner AndOnRaw(on string) Oner AndOnSymbol(field, symbol string, value interface{}) Oner AndOnIn(field string, value interface{}) Oner AndOnNotIn(field string, value interface{}) Oner Where(field string, value interface{}) Wherer WhereRaw(where string) Wherer WhereSymbol(field, symbol string, value interface{}) Wherer WhereIn(field string, value interface{}) Wherer WhereNotIn(field string, value interface{}) Wherer Join(tableName string) Joiner LeftJoin(tableName string) Joiner RightJoin(tableName string) Joiner GroupBy(field ...string) GroupByer Count() int64 Get() lib.SqlRows Find() lib.SqlRow OrderBy(orderBy string) OrderByer Limit(offset, count int) Limiter Union(model Modeler) Unioner Pager(page, pageSize int) (lib.SqlRows, lib.SqlRow) Update(data lib.SqlIn) int64 }
Oner on连接条件
type OrderByer ¶
type OrderByer interface { Get() lib.SqlRows Find() lib.SqlRow Limit(offset, count int) Limiter Pager(page, pageSize int) (lib.SqlRows, lib.SqlRow) }
OrderByer 排序
type SlaveDB ¶
type SlaveDB struct { Name string `json:"name"` DatabaseName string `json:"databaseName"` UserName string `json:"userName"` Password string `json:"password"` Host string `json:"host"` Port string `json:"port"` Charset string `json:"charset"` MaxOpenConns int `json:"maxOpenConns"` MaxIdleConns int `json:"maxIdleConns"` MaxLifetime int `json:"maxLifetime"` Prefix string `json:"prefix"` Suffix string `json:"suffix"` }
Slave 从库配置数据
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table 操作表
func (*Table) InsertOnDuplicate ¶
InsertOnDuplicate 如果你插入的记录导致一个UNIQUE索引或者primary key(主键)出现重复,那么就会认为该条记录存在,则执行update语句而不是insert语句,反之,则执行insert语句而不是更新语句。
type Tabler ¶
type Tabler interface { SetDB(db *DB) GetDB() *DB Insert(row lib.SqlIn) int64 Replace(row lib.SqlIn) int64 InsertOnDuplicate(row lib.SqlIn, updateRow lib.SqlIn) int64 Drop() int64 Truncate() int64 Optimize() int64 Delete(onParams []interface{}, where string, whereParams ...interface{}) int64 Update(row lib.SqlIn, onParams []interface{}, where string, whereParams ...interface{}) int64 SelectByHasWhere(fields string, where string, hasWhere bool, whereParams ...interface{}) lib.SqlRows Select(fields string, where string, whereParams ...interface{}) lib.SqlRows GetLastSql() string GetSqlInfo() (string, []interface{}) }
Tabler 表操作接口
type Unioner ¶
type Unioner interface { Count() int64 Get() lib.SqlRows Find() lib.SqlRow OrderBy(orderBy string) OrderByer Limit(offset, count int) Limiter Pager(page, pageSize int) (lib.SqlRows, lib.SqlRow) }
Unioner
type Wherer ¶
type Wherer interface { AndWhere(field string, value interface{}) Wherer AndWhereRaw(where string) Wherer AndWhereSymbol(field, symbol string, value interface{}) Wherer AndWhereIn(field string, value interface{}) Wherer AndWhereNotIn(field string, value interface{}) Wherer OrWhere(field string, value interface{}) Wherer OrWhereRaw(where string) Wherer OrWhereSymbol(field, symbol string, value interface{}) Wherer OrWhereIn(field string, value interface{}) Wherer OrWhereNotIn(field string, value interface{}) Wherer GroupBy(field ...string) GroupByer Get() lib.SqlRows Find() lib.SqlRow Count() int64 OrderBy(orderBy string) OrderByer Limit(offset, count int) Limiter Union(model Modeler) Unioner Pager(page, pageSize int) (lib.SqlRows, lib.SqlRow) Update(data lib.SqlIn) int64 Delete() int64 SoftDel() int64 }
Wherer 条件接口