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{})
- type Config
- type Crud
- type DB
- func (db *DB) Create(table string, data interface{})
- func (db *DB) CreateDataResID(table string, params cmap.CMap) (id uint64, err error)
- func (db *DB) CreateFormData(table string, params cmap.CMap) error
- func (db *DB) CreateMore(table string, model interface{}, data interface{})
- func (db *DB) Delete(table string, id interface{})
- func (db *DB) ExecSQL(sql string, args ...interface{})
- func (db *DB) Get(gt *GT)
- func (db *DB) GetByID(gt *GT, id interface{})
- func (db *DB) GetBySQLSearch(data interface{}, sql, sqlNt string, clientPage, everyPage int64, ...) (pager result.Pager)
- func (db *DB) GetBySearch(gt *GT) (pager result.Pager)
- func (db *DB) GetDataBySelectSQLSearch(gt *GT) (pager result.Pager)
- func (db *DB) GetMoreBySearch(gt *GT) (pager result.Pager)
- func (db *DB) GetMoreData(gt *GT)
- func (db *DB) InitColumns(param *Params)
- func (db *DB) NewDB()
- func (db *DB) Update(gt *GT)
- func (db *DB) 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() *DB
- 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 Distinct(Distinct string) Param
- func Inner(InnerTables ...string) Param
- func KeyModel(KeyModel interface{}) Param
- func Left(LeftTable ...string) Param
- func Model(Model interface{}) Param
- func SubSQL(SubSQL ...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+"
Variables ¶
This section is empty.
Functions ¶
func GetColSQLAlias ¶
GetColSQLAlias select * replace add alias
func GetInsertSQL ¶
GetInsertSQL get insert sql
func GetMoreTableColumnSQL ¶
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
Types ¶
type Crud ¶
type Crud interface { // Init init crud Init(param *Params) // DB db DB() *DB // Params new/replace param // return param Params(param ...Param) Crud // GetBySearch get url params // like form data GetBySearch(params cmap.CMap) Crud // search single table 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, more tables inner/left join // Delete delete by id/ids Delete(id interface{}) Crud // delete // UpdateForm 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 // Update 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(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 // Select Search pager, params only support Pager and Mock 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 interface
type DB ¶ added in v1.10.0
DB tool
func (*DB) CreateDataResID ¶ added in v1.30.30
CreateDataResID create data return id
func (*DB) CreateFormData ¶ added in v1.30.30
CreateFormData via form data create
func (*DB) CreateMore ¶ added in v1.30.30
CreateMore data must array type more data create single table also can use Create array
func (*DB) GetBySQLSearch ¶ added in v1.30.30
func (db *DB) GetBySQLSearch(data interface{}, sql, sqlNt string, clientPage, everyPage int64, args []interface{}) (pager result.Pager)
GetBySQLSearch get sql search data clientPage: default 1 everyPage: default 10 if clientPage or everyPage < 0, return all
func (*DB) GetBySearch ¶ added in v1.30.30
GetBySearch single table return search info
func (*DB) GetDataBySelectSQLSearch ¶ added in v1.30.30
GetDataBySelectSQLSearch select sql search
func (*DB) GetMoreBySearch ¶ added in v1.30.30
GetMoreBySearch 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 (*DB) InitColumns ¶ added in v1.30.30
InitColumns init db table columns map
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()
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()
GetSearchSQL search sql default order by id desc
func (*GT) GetSelectSearchSQL ¶ added in v1.20.6
func (gt *GT) GetSelectSearchSQL()
GetSelectSearchSQL select sql
type Mysql ¶ added in v1.10.0
type Mysql struct {
// contains filtered or unexported fields
}
Mysql implement Crud
func (*Mysql) CreateMore ¶ added in v1.10.0
CreateMore can use Create replace
func (*Mysql) GetBySearch ¶ added in v1.10.0
GetBySearch pager info
func (*Mysql) GetMoreBySearch ¶ added in v1.10.0
GetMoreBySearch 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 }
Params crud params