|
|
@ -3,13 +3,11 @@ package template
|
|
|
|
// Insert defines a template for insert code in model
|
|
|
|
// Insert defines a template for insert code in model
|
|
|
|
var Insert = `
|
|
|
|
var Insert = `
|
|
|
|
func (m *default{{.upperStartCamelObject}}Model) Insert(ctx context.Context, data *{{.upperStartCamelObject}}) (sql.Result,error) {
|
|
|
|
func (m *default{{.upperStartCamelObject}}Model) Insert(ctx context.Context, data *{{.upperStartCamelObject}}) (sql.Result,error) {
|
|
|
|
{{if .withCache}}{{if .containsIndexCache}}{{.keys}}
|
|
|
|
{{if .withCache}}{{.keys}}
|
|
|
|
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
|
|
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
|
|
query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
|
|
|
|
query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
|
|
|
|
return conn.ExecCtx(ctx, query, {{.expressionValues}})
|
|
|
|
return conn.ExecCtx(ctx, query, {{.expressionValues}})
|
|
|
|
}, {{.keyValues}}){{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
|
|
|
|
}, {{.keyValues}}){{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
|
|
|
|
ret,err:=m.ExecNoCacheCtx(ctx, query, {{.expressionValues}})
|
|
|
|
|
|
|
|
{{end}}{{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
|
|
|
|
|
|
|
|
ret,err:=m.conn.ExecCtx(ctx, query, {{.expressionValues}}){{end}}
|
|
|
|
ret,err:=m.conn.ExecCtx(ctx, query, {{.expressionValues}}){{end}}
|
|
|
|
return ret,err
|
|
|
|
return ret,err
|
|
|
|
}
|
|
|
|
}
|
|
|
|