Documentation ¶
Index ¶
- Constants
- func GetColParamSQL(model interface{}) (sql string)
- func GetColSQL(model interface{}) (sql string)
- func GetColSQLAlias(model interface{}, alias string) (sql string)
- func GetDataSQL(gt *GT) (sql string, args []interface{})
- func GetInsertSQL(table string, params cmap.CMap) (sql string, args []interface{})
- func GetMoreDataSQL(gt *GT)
- func GetMoreTableColumnSQL(model interface{}, tables ...string) (sql string)
- func GetParams(data interface{}) (params []interface{})
- func GetReflectTag(reflectType reflect.Type, buf *bytes.Buffer)
- func GetReflectTagAlias(ref reflect.Type, buf *bytes.Buffer, alias string)
- func GetReflectTagMore(ref reflect.Type, buf *bytes.Buffer, tables ...string)
- func GetSearchSQL(gt *GT) (sqlNt, sql string, clientPage, everyPage int64, args []interface{})
- func GetSelectSearchSQL(gt *GT) (sqlNt, sql string, clientPage, everyPage int64)
- func GetUpdateSQL(table string, params cmap.CMap) (sql string, args []interface{})
- type Crud
- type DBTool
- func (db *DBTool) CreateData(table string, data interface{})
- func (db *DBTool) CreateDataResID(table string, params cmap.CMap) (id uint64, err error)
- func (db *DBTool) CreateFormData(table string, params cmap.CMap) error
- func (db *DBTool) CreateMoreData(table string, model interface{}, data interface{})
- func (db *DBTool) Delete(table string, id interface{})
- func (db *DBTool) ExecSQL(sql string, args ...interface{})
- func (db *DBTool) GetBasicTypesData(typ reflect.Type, data interface{}, sql string, args ...interface{})
- func (db *DBTool) GetData(gt *GT)
- func (db *DBTool) GetDataByID(gt *GT, id interface{})
- func (db *DBTool) GetDataByName(data interface{}, name, value string) (err error)
- func (db *DBTool) GetDataBySQL(data interface{}, sql string, args ...interface{})
- func (db *DBTool) GetDataBySQLSearch(data interface{}, sql, sqlNt string, clientPage, everyPage int64, ...) (pager result.Pager)
- func (db *DBTool) GetDataBySearch(gt *GT) (pager result.Pager)
- func (db *DBTool) GetDataBySelectSQLSearch(gt *GT) (pager result.Pager)
- func (db *DBTool) GetMoreData(gt *GT)
- func (db *DBTool) GetMoreDataBySearch(gt *GT) (pager result.Pager)
- func (db *DBTool) NewDB()
- func (db *DBTool) UpdateData(gt *GT)
- func (db *DBTool) UpdateFormData(table string, params cmap.CMap) (err error)
- func (db *DBTool) UpdateStructData(data interface{}) (err error)
- type GT
- type Mysql
- func (c *Mysql) Begin() Crud
- func (c *Mysql) Commit() Crud
- func (c *Mysql) Create() Crud
- func (c *Mysql) CreateForm(params cmap.CMap) error
- func (c *Mysql) CreateMore() Crud
- func (c *Mysql) DB() *DBTool
- func (c *Mysql) Delete(id interface{}) Crud
- func (c *Mysql) Error() error
- func (c *Mysql) Exec() Crud
- func (c *Mysql) From(query string) Crud
- func (c *Mysql) GetByData(params cmap.CMap) Crud
- func (c *Mysql) GetByID(id interface{}) Crud
- func (c *Mysql) GetBySearch(params cmap.CMap) Crud
- func (c *Mysql) GetMoreByData(params cmap.CMap) Crud
- func (c *Mysql) GetMoreBySearch(params cmap.CMap) Crud
- func (c *Mysql) Group(query string) Crud
- func (c *Mysql) Init(param *Params)
- func (c *Mysql) Pager() result.Pager
- func (c *Mysql) Params(params ...Param) Crud
- func (c *Mysql) Rollback() Crud
- func (c *Mysql) RollbackTo(name string) Crud
- func (c *Mysql) RowsAffected() int64
- func (c *Mysql) SavePoint(name string) Crud
- func (c *Mysql) Search(params cmap.CMap) Crud
- func (c *Mysql) Select(q interface{}, args ...interface{}) Crud
- func (c *Mysql) Single() Crud
- func (c *Mysql) Update() Crud
- func (c *Mysql) UpdateForm(params cmap.CMap) error
- type Param
- func Data(Data interface{}) Param
- func Inner(InnerTables ...string) Param
- func InnerTable(InnerTables []string) Param
- func KeyModel(KeyModel interface{}) Param
- func Left(LeftTable ...string) Param
- func LeftTable(LeftTable []string) Param
- func Model(Model interface{}) Param
- func SubSQL(SubSQL ...string) Param
- func SubWhereSQL(WhereSQL ...string) Param
- func Table(Table string) Param
- func WhereSQL(WhereSQL string, args ...interface{}) Param
- type Params
Constants ¶
const Version = "1.20.0+"
Variables ¶
This section is empty.
Functions ¶
func GetColSQL ¶
func GetColSQL(model interface{}) (sql string)
根据model中表模型的json标签获取表字段 将select* 变为对应的字段名
func GetColSQLAlias ¶
根据model中表模型的json标签获取表字段 将select* 中'*'变为对应的字段名 增加别名,表连接问题
func GetInsertSQL ¶
传入数据库表名 插入语句拼接
func GetMoreDataSQL ¶ added in v1.10.0
func GetMoreDataSQL(gt *GT)
More Table params: innerTables is inner join tables, must even number params: leftTables is left join tables return: select sql table1 as main table, include other tables_id(foreign key)
func GetMoreTableColumnSQL ¶
select * replace select more tables tables : table name / table alias name 主表放在tables中第一个, 紧接着为主表关联的外键表名(无顺序)
func GetParams ¶
func GetParams(data interface{}) (params []interface{})
get data value like GetColSQL
func GetReflectTagAlias ¶
层级递增解析tag, 别名
func GetReflectTagMore ¶
层级递增解析tag, more tables
func GetSearchSQL ¶
分页参数不传, 查询所有 默认根据id倒序 单张表
func GetSelectSearchSQL ¶
select sql
Types ¶
type Crud ¶
type Crud interface { // init crud Init(param *Params) // DB // Deprecated, use gt.DB() replace DB() *DBTool // new/replace param // return param Params(param ...Param) Crud // get url params // like form data GetBySearch(params cmap.CMap) Crud // search GetByData(params cmap.CMap) Crud // get data no search GetMoreByData(params cmap.CMap) Crud // get data more table no search GetByID(id interface{}) Crud // by id GetMoreBySearch(params cmap.CMap) Crud // more search // delete by id/ids Delete(id interface{}) Crud // delete // crud and search id // form data // [create/update] future all will use json replace form request // form will not update UpdateForm(params cmap.CMap) error // update CreateForm(params cmap.CMap) error // create // crud and search id // json data Update() Crud // update Create() Crud // create, include res insert id CreateMore() Crud // create more, data must array type, single table // select Select(q interface{}, args ...interface{}) Crud // select sql From(query string) Crud // from sql, if use search, From must only once Group(query string) Crud // the last group by Search(params cmap.CMap) Crud // search pager Single() Crud // no search Exec() Crud // exec insert/update/delete sql Error() error // crud error RowsAffected() int64 // inflect rows Pager() result.Pager // search pager Begin() Crud // start a transaction Commit() Crud // commit a transaction Rollback() Crud // rollback a transaction SavePoint(name string) Crud // save a point RollbackTo(name string) Crud // rollback to point }
crud is db driver extend
type DBTool ¶
DB tool
func (*DBTool) CreateDataResID ¶
创建数据,通用 返回id,事务,慎用 业务少可用
func (*DBTool) CreateFormData ¶
via form data create
func (*DBTool) CreateMoreData ¶
data must array type more data create single table
func (*DBTool) GetBasicTypesData ¶ added in v1.9.4
func (*DBTool) GetDataByName ¶
获得数据,根据name条件 Deprecated
func (*DBTool) GetDataBySQL ¶
获得数据,根据sql语句,无分页
func (*DBTool) GetDataBySQLSearch ¶
func (db *DBTool) GetDataBySQLSearch(data interface{}, sql, sqlNt string, clientPage, everyPage int64, args []interface{}) (pager result.Pager)
获得数据,根据sql语句,分页 args : sql参数'?' sql, sqlNt args 相同, 共用args
func (*DBTool) GetDataBySearch ¶
获得数据,分页/查询
func (*DBTool) GetDataBySelectSQLSearch ¶
select sql search
func (*DBTool) GetMoreDataBySearch ¶
More Table params: innerTables is inner join tables params: leftTables is left join tables return: search info table1 as main table, include other tables_id(foreign key)
func (*DBTool) UpdateFormData ¶
via form data update
func (*DBTool) UpdateStructData ¶
结合struct修改
type GT ¶
type GT struct { *Params // CMap CMaps cmap.CMap // params // select sql Select string // select sql From string // only once Group string // the last group Args []interface{} // contains filtered or unexported fields }
GT SQL struct
type Mysql ¶ added in v1.10.0
type Mysql struct {
// contains filtered or unexported fields
}
implement Crud
func (*Mysql) CreateForm ¶ added in v1.10.0
create
func (*Mysql) CreateMore ¶ added in v1.10.0
== json data == create more
func (*Mysql) GetBySearch ¶ added in v1.10.0
search pager info
func (*Mysql) GetMoreBySearch ¶ added in v1.10.0
the same as search more tables
func (*Mysql) RollbackTo ¶ added in v1.20.0
func (*Mysql) RowsAffected ¶ added in v1.10.0
type Param ¶
type Param func(*Params)
type Params ¶
type Params struct { // attributes InnerTable []string // inner join tables LeftTable []string // left join tables Table string // table name Model interface{} // table model, like User{} KeyModel interface{} // key like model Data interface{} // table model data, like var user User{}, it is 'user', it store real data // sub query SubSQL string // SubQuery SQL // where WhereSQL string // Where SQL // contains filtered or unexported fields }
crud params