2016-03-23 07:18:41 +01:00
|
|
|
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
|
2016-03-18 12:26:48 +01:00
|
|
|
// {{$tableNameSingular}}Insert inserts a single record.
|
|
|
|
func {{$tableNameSingular}}Insert(db boil.DB, o *{{$tableNameSingular}}) (int, error) {
|
2016-02-23 13:38:24 +01:00
|
|
|
if o == nil {
|
2016-03-23 07:18:41 +01:00
|
|
|
return 0, errors.New("{{.PkgName}}: no {{.Table.Name}} provided for insertion")
|
2016-02-23 13:38:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var rowID int
|
2016-03-23 07:18:41 +01:00
|
|
|
err := db.QueryRow(`INSERT INTO {{.Table.Name}} ({{insertParamNames .Table.Columns}}) VALUES({{insertParamFlags .Table.Columns}}) RETURNING id`, {{insertParamVariables "o." .Table.Columns}}).Scan(&rowID)
|
2016-02-23 13:38:24 +01:00
|
|
|
|
|
|
|
if err != nil {
|
2016-03-23 07:18:41 +01:00
|
|
|
return 0, fmt.Errorf("{{.PkgName}}: unable to insert {{.Table.Name}}: %s", err)
|
2016-02-23 13:38:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return rowID, nil
|
|
|
|
}
|