2016-03-02 05:05:25 +01:00
|
|
|
{{- $tableName := .Table -}}
|
2016-03-01 17:34:57 +01:00
|
|
|
// {{titleCase $tableName}}Insert inserts a single record.
|
|
|
|
func {{titleCase $tableName}}Insert(db boil.DB, o *{{titleCase $tableName}}) (int, error) {
|
2016-02-23 13:38:24 +01:00
|
|
|
if o == nil {
|
2016-03-16 15:33:58 +01:00
|
|
|
return 0, errors.New("{{.PkgName}}: no {{$tableName}} provided for insertion")
|
2016-02-23 13:38:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var rowID int
|
2016-03-02 05:05:25 +01:00
|
|
|
err := db.QueryRow(`INSERT INTO {{$tableName}} ({{insertParamNames .Columns}}) VALUES({{insertParamFlags .Columns}}) RETURNING id`)
|
2016-02-23 13:38:24 +01:00
|
|
|
|
|
|
|
if err != nil {
|
2016-03-16 15:33:58 +01:00
|
|
|
return 0, fmt.Errorf("{{.PkgName}}: unable to insert {{$tableName}}: %s", err)
|
2016-02-23 13:38:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return rowID, nil
|
|
|
|
}
|