gt

package module
v1.30.9 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2021 License: MIT Imports: 27 Imported by: 0

README

gt 2.0

api快速开发业务框架, 模型生成, 通用增删改查, 支持多表连接

解决了什么

不仅仅是日常开发中crud,更是解决了绝大多数情况下的多表连接处理逻辑,三步crud(包含多表)

如何进行多表的crud

// https://github.com/dreamlu/gt-crud/blob/master/models/order/order.go
// order model
type Order struct {
	models.AdminCom
	ClientID uint64 `json:"client_id" gorm:"type:bigint(20);INDEX:查询索引client_id"` // 客户id
	// 0待付款(取消支付),1待发货,2待收货,3已完成,4退款完成,5申请退款中,6拒绝退款,7待评价
	Status     *int8   `json:"status" gorm:"type:tinyint(2);DEFAULT:0"`
	Money      float64 `json:"money" gorm:"type:decimal(10,2)"`       // 付款金额
	OutTradeNo string  `json:"out_trade_no" gorm:"type:varchar(50)"` // 商户订单号(退款等用)
}

// order detail
type OrderD struct {
	Order
	ClientName string `json:"client_name"` // client.name
}

// 分页列表,搜索和排序等集成
func (c *Order) GetMoreBySearch(params cmap.CMap) interface{} {
	var or []OrderD
	var crud = gt.NewCrud(
		gt.Inner("order", "client"),
		//gt.Left("order", "service"),
		gt.Model(OrderD{}),
		gt.Data(&or),
	)

	cd := crud.GetMoreBySearch(params)
	if cd.Error() != nil {
		return result.GetError(cd.Error())
	}

	return result.GetSuccessPager(or, cd.Pager())
}
demo:

gt-crud (单机)
micro-go (微服务)

API

API Examples

Model

// user model
type User struct {
	ID         uint64     `json:"id"`
	Name       string     `json:"name"`
	Createtime time.CTime `json:"createtime"`
}

// service model
type Service struct {
	ID   uint64 `json:"id"`
	Name string `json:"name"`
}

// order model
type Order struct {
	ID         uint64     `json:"id"`
	UserID     int64      `json:"user_id"`    // user id
	ServiceID  int64      `json:"service_id"` // service table id
	Createtime time.CTime `json:"createtime"` // createtime
}

// order detail
type OrderD struct {
	Order
	UserName    string `json:"user_name"`    // user table column name
	ServiceName string `json:"service_name"` // service table column `name`
}

    // select more
    // 多表查询
	// get more search
	var params = make(cmap.CMap)
	params.Add("user_id", "1")
	//params.Add("key", "梦") // key word
	params.Add("clientPage", "1") // 第一页
	params.Add("everyPage", "2") // 每页2条
	var or []*OrderD
	crud := NewCrud(
		Inner("order", "user", "order", "service"),
		//Left("order", "service"),
		Model(OrderD{}),
		Data(&or),
		SubWhereSQL("1 = 1", "2 = 2", ""),
	)
	err := crud.GetMoreBySearch(params).Error()
	if err != nil {
		log.Println(err)
	}
	t.Log("\n[User Info]:", or[0])
    
// output:
    TestGetMoreDataBySearch: db_test.go:243: 
        [User Info]: &{{1 1 1 "2019-01-28 15:07:06"} 梦sql 服务名称}
--- PASS: TestGetMoreDataBySearch (0.00s)
PASS

Struct Gt

gt:"sub_sql", gt:"ignore", gt:"-"<忽略该字段解析,<可进行子查询>>

type Client struct {
	models.AdminCom
	Name    string `gorm:"type:varchar(30)" json:"name" valid:"required,len=2-20"` // 昵称
	Openid  string `json:"openid" gorm:"varchar(30);UNIQUE_INDEX:openid已存在"`       // openID
	HeadImg string `json:"head_img"`                                               // 头像
}

type ClientD struct {
	Client      // 头像
	BuyNum int8 `json:"buy_num" gt:"sub_sql"` // 购买次数
}
// search
func (c *Client) GetBySearch(params cmap.CMap) interface{} {

	buyNumSQL := "(select count(*) from `order` where client_id = `client`.id and status >= 3) as buy_num"
	var datas []*ClientD
	crud.Params(
		gt.Data(&datas),
		gt.SubSQL(buyNumSQL),
		)
	cd := crud.GetBySearch(params)
	if cd.Error() != nil {
		//log.Log.Error(err.Error())
		return result.CError(cd.Error())
	}
	return result.GetSuccessPager(datas, cd.Pager())
}
// output:
print sql: select `id`,`createtime`,`admin_id`,`name`,`openid`,`head_img`,(select count(*) from `order` where client_id = `client`.id and status >= 3) as buy_num from `client` order by id desc limit 0, 2 

gt:"field:fieldName"<特殊情况下,替代json解析>

    type CVB struct {
		ID          int64      `gorm:"type:bigint(20)" json:"id"`
		ClientVipID int64      `gorm:"type:bigint(20)" json:"client_vip_id"`
		ShopId      int64      `gorm:"type:bigint(20)" json:"shop_id"`
	}

	// 客户行为详情
	type CVBDe struct {
		CVB
		ClientName    string `json:"client_name"`
		VipType       int64  `json:"vip_type" gt:"sub_sql"`
		IsSp          int64  `json:"-" gt:"field:is_sp"`
	}
	gt := &GT{
		Params: &Params{
			InnerTable: []string{"client_vip_behavior", "client_vip", "client_vip", "client"},
			Model:      CVBDe{},
		},
	}
	sqlNt, sql, _, _, _ := GetMoreSearchSQL(gt)
	t.Log(sqlNt)
	t.Log(sql)
	// output:
	TestGetMoreSearchSQL: db_test.go:267: select count(`client_vip_behavior`.id) as total_num from `client_vip_behavior` inner join `client_vip` on `client_vip_behavior`.`client_vip_id`=`client_vip`.`id`  inner join `client` on `client_vip`.`client_id`=`client`.`id` 
	TestGetMoreSearchSQL: db_test.go:268: select `client_vip_behavior`.`id`,`client_vip_behavior`.`client_vip_id`,`client_vip_behavior`.`shop_id`,`client`.`name` as client_name,`client_vip_behavior`.`is_sp` from `client_vip_behavior` inner join `client_vip` on `client_vip_behavior`.`client_vip_id`=`client_vip`.`id`  inner join `client` on `client_vip`.`client_id`=`client`.`id`  order by `client_vip_behavior`.id desc 

Crud Request

var crud = gt.NewCrud(
	gt.Model(Client{}),
)

// get data, by id
func (c *Client) GetByID(id string) (*Client, error) {

	var data Client // not use *Client
	crud.Params(gt.Data(&data))
	if err := crud.GetByID(id).Error(); err != nil {
		return nil, err
	}
	return &data, nil
}

// get data, limit and search
// clientPage 1, everyPage 10 default
func (c *Client) GetBySearch(params cmap.CMap) (datas []*Client, pager result.Pager, err error) {
	//var datas []*Client
	crud.Params(gt.Data(&datas))
	cd := crud.GetBySearch(params)
	if cd.Error() != nil {
		return nil, pager, cd.Error()
	}
	return datas, cd.Pager(), nil
}

// id支持批量删除(逗号分割), 如: id = 12,13,14
// delete data, by id
func (c *Client) Delete(id string) error {

	return crud.Delete(id).Error()
}

// update data
func (c *Client) Update(data *Client) (*Client, error) {

	crud.Params(gt.Data(data))
	if err := crud.Update().Error(); err != nil {
		return nil, err
	}
	return data, nil
}

// create data
func (c *Client) Create(data *Client) (*Client, error) {

	crud.Params(gt.Data(data))
	if err := crud.Create().Error(); err != nil {
		return nil, err
	}
	return data, nil
}

Crud More

多表查询支持多表/同一个mysql跨数据库查询/mock假数据等等
1.GetMoreBySearch

	// 多表查询
	// get more search
	var params = make(cmap.CMap)
	//params.Add("user_id", "1")
	//params.Add("key", "梦") // key work
	params.Add("clientPage", "1")
	params.Add("everyPage", "2")
	//params.Add("mock", "1") // mock data
	var or []*OrderD
	crud := NewCrud(
		// 支持同一个mysql多数据库跨库查询
		Inner("gt.order", "user"),
		Left("order", "service"),
		Model(OrderD{}),
		Data(&or),
		//SubWhereSQL("1 = 1", "2 = 2", ""),
	)
	err := crud.GetMoreBySearch(params).Error()
	if err != nil {
		log.Println(err)
	}
	t.Log("\n[User Info]:", or)

2.GetMoreByData

	var or []*OrderD
	cd := NewCrud(
		// 支持同一个mysql多数据库跨库查询
		Inner("order", "gt.user"),
		Left("order", "service"),
		Model(OrderD{}),
		Data(&or),
		KeyModel(OrderD{}),
	)
	err := cd.GetMoreByData(cmap.NewCMap()).Error()
	if err != nil {
		t.Error(err)
	}

CreateMore

// 批量创建
func TestCreateMoreDataJ(t *testing.T) {
    type UserPar struct {
		Name       string     `json:"name"`
		Createtime time.CTime `json:"createtime"`
	}
	type User struct {
		ID uint64 `json:"id"`
		UserPar
	}
	
	var up = []UserPar{
		{Name: "测试1", Createtime: time.CTime(time2.Now())},
		{Name: "测试2"},
	}
	crud := NewCrud(
		//Table("user"),
		Model(UserPar{}),
		Data(up),
		//SubSQL("(asdf) as a","(asdfa) as b"),
	)

	err := crud.CreateMore()
	t.Log(err)
}

  • 多模式配置文件

配置方式: conf/app.yaml 中 devMode = dev 对应conf/app-dev.yaml

GetDevMode

    type dba struct {
    	User        string
    	Password    string
    	Host        string
    	Name        string
    	MaxIdleConn int
    	MaxOpenConn int
    	// db log mode
    	Log bool
    }
    config := gt.Configger()
    dbS := &dba{
        user:     config.GetString("app.db.user"),
        password: config.GetString("app.db.password"),
        host:     config.GetString("app.db.host"),
        name:     config.GetString("app.db.name"),
    }
    // or
    dbS := &dba{}
    gt.Configger().GetStruct("app.db", dbS)

CacheManager

	ce = gt.NewCache()
	data := CacheModel{
		Time: 50 * CacheMinute,
		Data: user,
	}

	// key can use user.ID,user.Name,user
	// because it can be interface
	// set
	err := ce.Set(user, data)
	t.Log("set err: ", err)

	// get
	reply, _ := ce.Get(user)
	t.Log("user data :", reply.Data)

AesEnDe

log.Println("[加密测试]:", AesEn("123456"))
log.Println("[解密测试]:", AesDe("lIEbR7cEp2U10gtM0j8dCg=="))

Time

// 时间格式化2006-01-02 15:04:05
type CTime time.Time
// 时间格式化2006-01-02
type CDate time.Time
// 时间格式化2006-01-02 15:04:05.000
type CNTime time.Time
// 时间格式化 15:04:05
// ps gorm type生成bug,不填写type,默认即可
type CSTime time.Time

JSONType

// 返回json类型
type CJSON []byte

Validator

字段验证

func TestValidator(t *testing.T) {
    type Test struct {
		ID   int64  `json:"id" gt:"valid:required,min=0,max=5"`
		Name string `json:"name" gt:"valid:required,len=2-5;trans:用户名"`
	}

	// json data
	var test = Test{
		ID:   6,
		Name: "梦",
	}
	t.Log(Valid(test))

	// form data
	var maps = cmap.NewCMap()
	maps["name"] = append(maps["name"], "梦")
	info := ValidForm(maps, Test{})
	//t.Log(info == nil)
	t.Log(info)
}

添加自定义规则

// add your custom rule
func TestCustomizeValid(t *testing.T) {
	type Test struct {
		Name string `json:"name" gt:"valid:required,large=3;trans:用户名"`
	}

	// json data
	var test = Test{
		Name: "梦sss",
	}
	t.Log(Valid(test))

	AddRule("large", func(rule string, data interface{}) error {
		num, _ := strconv.Atoi(rule)
		if v, ok := data.(string); ok {
			if length(v) > num {
				return errors.New("最大" + rule)
			}
		}
		return nil
	})

	t.Log(Valid(test))
}

CustomLog

func TestNewFileLog(t *testing.T) {

	myLog.Info("项目路径", projectPath)
	for {
		time.Sleep(1 * time.Second)
		myLog.Error("测试")
	}
}

SnowflakeId

func TestId(t *testing.T) {
	id, err := NewID(1)
	if err != nil {
		log.Print(err)
		return
	}
	t.Log(id.String())
}

Msg

消息中间件nsq

前提: 运行nsq, 参考docker-compose.yaml

参考:nsq_test.go

Gsync

多线程池支持
参考:nsq_test.go
异步

	p = gsync.NewPool(100)
	read := func() {
		fmt.Printf("go func time: %d\n", time.Now().Unix())
		time.Sleep(time.Second)
	}

	// 多线程提交执行
	for i := 0; i < 1000; i++ {
		p.Submit(read)
	}
	time.Sleep(5*time.Second)

同步

	read := func() {
		fmt.Printf("go func time: %d\n", time.Now().Unix())
		time.Sleep(time.Second)
	}

	for i := 0; i < 10; i++ {
		p.Submit(read)
		readWait := func() interface{} {
			time.Sleep(time.Second)
			return i
		}

		t.Log(p.SubmitWait(readWait))
	}

Extend Examples

Crud Selectsql

    sql := "update `user` set name=? where id=?"
    t.Log("[Info]:", crud.Select(sql, "梦sql", 1).Exec())
    var user []*User
	cd := crud.Params(
		Data(&user),
		//ClientPage(1), // serch()分页需要
		//EveryPage(2),
	).
		Select("select *from user").
		Select("where id > 0")
	if true {
		cd.Select("and 1=1")
	}
	cd.Search() // 查询 + 分页
    t.Log(crud.Pager()) // Search()分页数据
	//cd.Single() // 注释Search使用Single()直接查询

Crud Update

	type UserPar struct {
		Name string `json:"name"`
	}
	crud := crud.Params(
		//Table("user"),
		Model(User{}),
		Data(&UserPar{
			//ID:   1,
			Name: "梦S",
		}),
	)
	t.Log(crud.Update().RowsAffected())
	t.Log(crud.Select("`name` = ?", "梦").Update().RowsAffected())
	t.Log(crud.Error())

Transcation

	cd := crud.Begin()
	cd.Params(
		Table("user"),
		Data(&User{
			ID:   11234,
			Name: "梦S",
		}),
	).Create()
	if cd.Error() != nil {
		cd.Rollback()
	}
	cd.Params(
		Data(&User{
			Name: "梦SSS2",
		})).Create()
	if cd.Error() != nil {
		cd.Rollback()
	}
	// add select sql test
	var u []User
	cd.Params(Data(&u)).Select("select * from `user`").Select("where 1=1").Single()
	cd.Params(Data(&u)).Select("select * from `user`").Select("where 1=1").Single()
	//cd.DB().Raw("select * from `user`").Scan(&u)

	cd.Commit()
	if cd.Error() != nil {
		cd.Rollback()
	}

Use Gorm

模型定义需遵循:
gt v1.20以前参考模型定义v1
gt v1.20+参考模型定义v2

// example 1:
// 根据模型定义自动生成表
gt.NewDBTool().AutoMigrate(&User{},&Order{})
// 直接使用gorm:
db := gt.NewCrud().DB()

Mock Data

使用mock参数, 生成随机数据, 将不会进行数据库查询

    GetBySearch(params cmap.CMap) Crud     // search
    GetByData(params cmap.CMap) Crud       // get data no search
    GetMoreBySearch(params cmap.CMap) Crud // more search    
    // 以上三种支持mock参数,传递的参数mock=1即可

ps:
1.不支持CJSON类型, 请使用tag: faker:"-"进行过滤
2.不支持图片等实体文件数据
3.默认随机生成,如有长度等其他要求,请参考:faker_test

Crud clone

// 关于crud的
一个crud = gt.NewCrud()对象中的参数是共享的,通用的增删改查针对同一张表可复用  
如果进行了表关联或改变了模型, 需要重新cd = gt.NewCrud(),否则继续使用crud容易影响到其他使用这个变量的地方
  • 约定
    1.必定有id字段
    2.模型结构体的json格式内容与表字段保持一致
    3.返回格式参考result
    4.多表关联命名, 模型中其他表字段命名: 他表名 + "_" + 他表字段名
    5.More相关接口同一个pkg和同一个Model尽量不要重复, 如有, 可通过换目录pkg或继承Model+制定gt.Table()解决
    n.crud更多用法参考crud_mysql_test

Documentation

Index

Constants

View Source
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

View Source
const Version = "2.0.0+"

Variables

This section is empty.

Functions

func GetColParamSQL

func GetColParamSQL(model interface{}) (sql string)

get col ?

func GetColSQL

func GetColSQL(model interface{}) (sql string)

select * replace

func GetColSQLAlias

func GetColSQLAlias(model interface{}, alias string) (sql string)

select * replace add alias

func GetInsertSQL

func GetInsertSQL(table string, params cmap.CMap) (sql string, args []interface{})

get insert sql

func GetMoreTableColumnSQL

func GetMoreTableColumnSQL(model interface{}, tables ...string) (sql string)

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

func GetUpdateSQL(table string, params cmap.CMap) (sql string, args []interface{})

get update sql

func New added in v1.20.6

func New(config Config) logger2.Interface

Types

type Config

type Config struct {
	SlowThreshold time.Duration
	Colorful      bool
	LogLevel      logger2.LogLevel
}

type Crud

type Crud interface {
	// init crud
	Init(param *Params)
	// DB
	DB() *DBTool
	// new/replace param
	// return param
	Params(param ...Param) Crud

	// 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 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                   // 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 is db driver extend

func NewCrud

func NewCrud(params ...Param) (crud Crud)

new crud

type DBTool

type DBTool struct {
	// db driver
	*gorm.DB
	// contains filtered or unexported fields
}

DB tool

func DB added in v1.10.0

func DB() *DBTool

single db

func (*DBTool) Create added in v1.20.6

func (db *DBTool) Create(table string, data interface{})

create single/array

func (*DBTool) CreateDataResID

func (db *DBTool) CreateDataResID(table string, params cmap.CMap) (id uint64, err error)

create data return id

func (*DBTool) CreateFormData

func (db *DBTool) CreateFormData(table string, params cmap.CMap) error

via form data create

func (*DBTool) CreateMore added in v1.20.6

func (db *DBTool) CreateMore(table string, model interface{}, data interface{})

data must array type more data create single table also can use Create array

func (*DBTool) Delete

func (db *DBTool) Delete(table string, id interface{})

delete

func (*DBTool) ExecSQL

func (db *DBTool) ExecSQL(sql string, args ...interface{})

exec sql

func (*DBTool) Get added in v1.20.6

func (db *DBTool) Get(gt *GT)

获得数据, no search

func (*DBTool) GetByID added in v1.20.6

func (db *DBTool) GetByID(gt *GT, id interface{})

get by id

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

func (db *DBTool) GetBySearch(gt *GT) (pager result.Pager)

single table return search info

func (*DBTool) GetDataBySelectSQLSearch

func (db *DBTool) GetDataBySelectSQLSearch(gt *GT) (pager result.Pager)

select sql search

func (*DBTool) GetMoreBySearch added in v1.20.6

func (db *DBTool) GetMoreBySearch(gt *GT) (pager result.Pager)

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) GetMoreData added in v1.10.0

func (db *DBTool) GetMoreData(gt *GT)

获得数据, no search

func (*DBTool) InitColumns added in v1.20.11

func (db *DBTool) InitColumns(param *Params)

init db table columns map

func (*DBTool) NewDB

func (db *DBTool) NewDB()

new db driver

func (*DBTool) Update added in v1.20.6

func (db *DBTool) Update(gt *GT)

update

func (*DBTool) UpdateFormData

func (db *DBTool) UpdateFormData(table string, params cmap.CMap) (err error)

via form data update

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) GetSQL added in v1.20.6

func (gt *GT) GetSQL()

get single sql

func (*GT) GetSearchSQL added in v1.20.6

func (gt *GT) GetSearchSQL()

search sql default order by id desc

func (*GT) GetSelectSearchSQL added in v1.20.6

func (gt *GT) GetSelectSearchSQL()

select sql

type Mysql added in v1.10.0

type Mysql struct {
	// contains filtered or unexported fields
}

implement Crud

func (*Mysql) Begin added in v1.10.0

func (c *Mysql) Begin() Crud

func (*Mysql) Commit added in v1.10.0

func (c *Mysql) Commit() Crud

func (*Mysql) Create added in v1.10.0

func (c *Mysql) Create() Crud

create

func (*Mysql) CreateForm added in v1.10.0

func (c *Mysql) CreateForm(params cmap.CMap) error

create

func (*Mysql) CreateMore added in v1.10.0

func (c *Mysql) CreateMore() Crud

== json data == create more

func (*Mysql) DB added in v1.10.0

func (c *Mysql) DB() *DBTool

func (*Mysql) Delete added in v1.10.0

func (c *Mysql) Delete(id interface{}) Crud

delete

func (*Mysql) Error added in v1.10.0

func (c *Mysql) Error() error

func (*Mysql) Exec added in v1.10.0

func (c *Mysql) Exec() Crud

func (*Mysql) From added in v1.10.0

func (c *Mysql) From(query string) Crud

func (*Mysql) Get added in v1.20.6

func (c *Mysql) Get(params cmap.CMap) Crud

func (*Mysql) GetByID added in v1.10.0

func (c *Mysql) GetByID(id interface{}) Crud

by id

func (*Mysql) GetBySearch added in v1.10.0

func (c *Mysql) GetBySearch(params cmap.CMap) Crud

search pager info

func (*Mysql) GetMore added in v1.20.6

func (c *Mysql) GetMore(params cmap.CMap) Crud

func (*Mysql) GetMoreBySearch added in v1.10.0

func (c *Mysql) GetMoreBySearch(params cmap.CMap) Crud

the same as search more tables

func (*Mysql) Group added in v1.10.0

func (c *Mysql) Group(query string) Crud

func (*Mysql) Init added in v1.20.0

func (c *Mysql) Init(param *Params)

init DBTool tool

func (*Mysql) Pager added in v1.10.0

func (c *Mysql) Pager() result.Pager

func (*Mysql) Params added in v1.10.0

func (c *Mysql) Params(params ...Param) Crud

func (*Mysql) Rollback added in v1.10.0

func (c *Mysql) Rollback() Crud

func (*Mysql) RollbackTo added in v1.20.0

func (c *Mysql) RollbackTo(name string) Crud

func (*Mysql) RowsAffected added in v1.10.0

func (c *Mysql) RowsAffected() int64

func (*Mysql) SavePoint added in v1.20.0

func (c *Mysql) SavePoint(name string) Crud

func (*Mysql) Search added in v1.10.0

func (c *Mysql) Search(params cmap.CMap) Crud

func (*Mysql) Select added in v1.10.0

func (c *Mysql) Select(q interface{}, args ...interface{}) Crud

create

func (*Mysql) Single added in v1.10.0

func (c *Mysql) Single() Crud

func (*Mysql) Update added in v1.10.0

func (c *Mysql) Update() Crud

update

func (*Mysql) UpdateForm added in v1.10.0

func (c *Mysql) UpdateForm(params cmap.CMap) error

update

type Param

type Param func(*Params)

func Data

func Data(Data interface{}) Param

func Distinct added in v1.20.9

func Distinct(Distinct string) Param

inner/left support distinct

func Inner added in v1.8.1

func Inner(InnerTables ...string) Param

func InnerTable

func InnerTable(InnerTables []string) Param

Deprecated

func KeyModel

func KeyModel(KeyModel interface{}) Param

func Left added in v1.8.1

func Left(LeftTable ...string) Param

func LeftTable

func LeftTable(LeftTable []string) Param

Deprecated

func Model

func Model(Model interface{}) Param

func SubSQL

func SubSQL(SubSQL ...string) Param

func SubWhereSQL

func SubWhereSQL(WhereSQL ...string) Param

Deprecated use WhereSQL replace

func Table

func Table(Table string) Param

func WhereSQL added in v1.20.0

func WhereSQL(WhereSQL string, args ...interface{}) Param

where sql and args, can not coexists with SubWhereSQL

func (Param) WhereSQL added in v1.20.0

func (p Param) WhereSQL(WhereSQL string, args ...interface{}) Param

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

Jump to

Keyboard shortcuts

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