2020-08-19 10:41:19 +08:00
|
|
|
package template
|
2020-07-29 17:11:41 +08:00
|
|
|
|
2021-02-26 16:11:47 +08:00
|
|
|
// Insert defines a template for insert code in model
|
2020-07-29 17:11:41 +08:00
|
|
|
var Insert = `
|
2021-11-07 22:44:37 +08:00
|
|
|
func (m *default{{.upperStartCamelObject}}Model) Insert(data *{{.upperStartCamelObject}}) (sql.Result,error) {
|
2020-10-11 21:55:44 +08:00
|
|
|
{{if .withCache}}{{if .containsIndexCache}}{{.keys}}
|
2020-10-21 14:59:35 +08:00
|
|
|
ret, err := m.Exec(func(conn sqlx.SqlConn) (result sql.Result, err error) {
|
2020-10-27 22:42:53 +08:00
|
|
|
query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
|
2020-10-11 21:55:44 +08:00
|
|
|
return conn.Exec(query, {{.expressionValues}})
|
2020-10-27 22:42:53 +08:00
|
|
|
}, {{.keyValues}}){{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
|
2020-10-21 14:59:35 +08:00
|
|
|
ret,err:=m.ExecNoCache(query, {{.expressionValues}})
|
2020-10-27 22:42:53 +08:00
|
|
|
{{end}}{{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
|
2020-10-21 14:59:35 +08:00
|
|
|
ret,err:=m.conn.Exec(query, {{.expressionValues}}){{end}}
|
|
|
|
return ret,err
|
2020-07-29 17:11:41 +08:00
|
|
|
}
|
|
|
|
`
|
2020-11-24 22:36:23 +08:00
|
|
|
|
2021-11-07 22:44:37 +08:00
|
|
|
// InsertMethod defines an interface method template for insert code in model
|
|
|
|
var InsertMethod = `Insert(data *{{.upperStartCamelObject}}) (sql.Result,error)`
|