2016-02-23 13:38:24 +01:00
|
|
|
{{- $tableName := .TableName -}}
|
2016-03-01 16:53:56 +01:00
|
|
|
// {{makeGoName $tableName}}Insert inserts a single record.
|
|
|
|
func {{makeGoName $tableName}}Insert(db boil.DB, o *{{makeGoName $tableName}}) (int, error) {
|
2016-02-23 13:38:24 +01:00
|
|
|
if o == nil {
|
2016-02-29 03:52:17 +01:00
|
|
|
return 0, errors.New("model: no {{$tableName}} provided for insertion")
|
2016-02-23 13:38:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var rowID int
|
2016-02-29 03:52:17 +01:00
|
|
|
err := db.QueryRow(`INSERT INTO {{$tableName}} ({{makeGoInsertParamNames .TableData}}) VALUES({{makeGoInsertParamFlags .TableData}}) RETURNING id`)
|
2016-02-23 13:38:24 +01:00
|
|
|
|
|
|
|
if err != nil {
|
2016-02-29 03:52:17 +01:00
|
|
|
return 0, fmt.Errorf("model: unable to insert {{$tableName}}: %s", err)
|
2016-02-23 13:38:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return rowID, nil
|
|
|
|
}
|