Documentation ¶
Index ¶
- Constants
- func GetColParamSQL(model interface{}) (sql string)
- func GetColSQL(model interface{}) (sql string)
- func GetColSQLAlias(model interface{}, alias string) (sql string)
- func GetInsertSQL(table string, params cmap.CMap) (sql string, args []interface{})
- func GetMoreTableColumnSQL(model interface{}, tables ...string) (sql string)
- func GetParams(data interface{}) (params []interface{})
- func GetUpdateSQL(table string, params cmap.CMap) (sql string, args []interface{})
- func New(config Config) logger2.Interface
- type Config
- type Crud
- type DBTool
- func (db *DBTool) Create(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) CreateMore(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) Get(gt *GT)
- func (db *DBTool) GetByID(gt *GT, id interface{})
- func (db *DBTool) GetBySQLSearch(data interface{}, sql, sqlNt string, clientPage, everyPage int64, ...) (pager result.Pager)
- func (db *DBTool) GetBySearch(gt *GT) (pager result.Pager)
- func (db *DBTool) GetDataBySelectSQLSearch(gt *GT) (pager result.Pager)
- func (db *DBTool) GetMoreBySearch(gt *GT) (pager result.Pager)
- func (db *DBTool) GetMoreData(gt *GT)
- func (db *DBTool) NewDB()
- func (db *DBTool) Update(gt *GT)
- func (db *DBTool) UpdateFormData(table string, params cmap.CMap) (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) Get(params cmap.CMap) Crud
- func (c *Mysql) GetByID(id interface{}) Crud
- func (c *Mysql) GetBySearch(params cmap.CMap) Crud
- func (c *Mysql) GetMore(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 ( Reset = "\033[0m" Red = "\033[31m" Green = "\033[32m" Yellow = "\033[33m" Blue = "\033[34m" Magenta = "\033[35m" Cyan = "\033[36m" White = "\033[37m" BlueBold = "\033[34;1m" MagentaBold = "\033[35;1m" RedBold = "\033[31;1m" YellowBold = "\033[33;1m" )
Colors
const Version = "2.0.0+"
Variables ¶
This section is empty.
Functions ¶
func GetColSQLAlias ¶
select * replace add alias
func GetInsertSQL ¶
get insert sql
func GetMoreTableColumnSQL ¶
select * replace select more tables tables : table name / table alias name first table must main table, like from a inner join b, first table is a
func GetParams ¶
func GetParams(data interface{}) (params []interface{})
get single struct data value
func GetUpdateSQL ¶
get update 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 Get(params cmap.CMap) Crud // get data no search GetMore(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 ¶
create data return id
func (*DBTool) CreateFormData ¶
via form data create
func (*DBTool) CreateMore ¶ added in v1.20.6
data must array type more data create single table also can use Create array
func (*DBTool) GetBySQLSearch ¶ added in v1.20.6
func (db *DBTool) GetBySQLSearch(data interface{}, sql, sqlNt string, clientPage, everyPage int64, args []interface{}) (pager result.Pager)
get sql search data clientPage: default 1 everyPage: default 10 if clientPage or everyPage < 0, return all
func (*DBTool) GetBySearch ¶ added in v1.20.6
single table return search info
func (*DBTool) GetDataBySelectSQLSearch ¶
select sql search
func (*DBTool) GetMoreBySearch ¶ added in v1.20.6
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)
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
func (*GT) GetMoreSQL ¶ added in v1.20.6
func (gt *GT) GetMoreSQL()
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 (*GT) GetSearchSQL ¶ added in v1.20.6
func (gt *GT) GetSearchSQL()
search sql default order by id desc
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