insert.go 1.1 KB

12345678910111213141516171819
  1. package template
  2. // Insert defines a template for insert code in model
  3. var Insert = `
  4. func (m *default{{.upperStartCamelObject}}Model) Insert(data {{.upperStartCamelObject}}) (sql.Result,error) {
  5. {{if .withCache}}{{if .containsIndexCache}}{{.keys}}
  6. ret, err := m.Exec(func(conn sqlx.SqlConn) (result sql.Result, err error) {
  7. query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
  8. return conn.Exec(query, {{.expressionValues}})
  9. }, {{.keyValues}}){{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
  10. ret,err:=m.ExecNoCache(query, {{.expressionValues}})
  11. {{end}}{{else}}query := fmt.Sprintf("insert into %s (%s) values ({{.expression}})", m.table, {{.lowerStartCamelObject}}RowsExpectAutoSet)
  12. ret,err:=m.conn.Exec(query, {{.expressionValues}}){{end}}
  13. return ret,err
  14. }
  15. `
  16. // InsertMethod defines a interface method template for insert code in model
  17. var InsertMethod = `Insert(data {{.upperStartCamelObject}}) (sql.Result,error)`