mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 18:00:24 +08:00
69a4d213a3
* fix #1205 * move builder into stores * remove xrom * Remove unused code * Remove unused code * refactor builderx to builder Co-authored-by: anqiansong <anqiansong@bytedance.com>
20 lines
1.1 KiB
Go
20 lines
1.1 KiB
Go
package template
|
|
|
|
// Insert defines a template for insert code in model
|
|
var Insert = `
|
|
func (m *default{{.upperStartCamelObject}}Model) Insert(data *{{.upperStartCamelObject}}) (sql.Result,error) {
|
|
{{if .withCache}}{{if .containsIndexCache}}{{.keys}}
|
|
ret, err := m.Exec(func(conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
|
|
return conn.Exec(query, {{.expressionValues}})
|
|
}, {{.keyValues}}){{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
|
|
ret,err:=m.ExecNoCache(query, {{.expressionValues}})
|
|
{{end}}{{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
|
|
ret,err:=m.conn.Exec(query, {{.expressionValues}}){{end}}
|
|
return ret,err
|
|
}
|
|
`
|
|
|
|
// InsertMethod defines an interface method template for insert code in model
|
|
var InsertMethod = `Insert(data *{{.upperStartCamelObject}}) (sql.Result,error)`
|