insert.go 960 B

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