update.go 858 B

1234567891011121314151617
  1. package template
  2. // Update defines a template for generating update codes
  3. var Update = `
  4. func (m *default{{.upperStartCamelObject}}Model) Update(data {{.upperStartCamelObject}}) error {
  5. {{if .withCache}}{{.keys}}
  6. _, err := m.Exec(func(conn sqlx.SqlConn) (result sql.Result, err error) {
  7. query := fmt.Sprintf("update %s set %s where {{.originalPrimaryKey}} = ?", m.table, {{.lowerStartCamelObject}}RowsWithPlaceHolder)
  8. return conn.Exec(query, {{.expressionValues}})
  9. }, {{.keyValues}}){{else}}query := fmt.Sprintf("update %s set %s where {{.originalPrimaryKey}} = ?", m.table, {{.lowerStartCamelObject}}RowsWithPlaceHolder)
  10. _,err:=m.conn.Exec(query, {{.expressionValues}}){{end}}
  11. return err
  12. }
  13. `
  14. // UpdateMethod defines an interface method template for generating update codes
  15. var UpdateMethod = `Update(data {{.upperStartCamelObject}}) error`