sqlboiler/cmds/templates/insert.tpl
Aaron 64ec06b4b4 Rename some functions.
- Use more efficient implementation of the template funcs.
2016-03-01 08:34:57 -08:00

17 lines
557 B
Smarty

{{- $tableName := .TableName -}}
// {{titleCase $tableName}}Insert inserts a single record.
func {{titleCase $tableName}}Insert(db boil.DB, o *{{titleCase $tableName}}) (int, error) {
if o == nil {
return 0, errors.New("model: no {{$tableName}} provided for insertion")
}
var rowID int
err := db.QueryRow(`INSERT INTO {{$tableName}} ({{insertParamNames .TableData}}) VALUES({{insertParamFlags .TableData}}) RETURNING id`)
if err != nil {
return 0, fmt.Errorf("model: unable to insert {{$tableName}}: %s", err)
}
return rowID, nil
}