sqlboiler/cmds/templates/insert.tpl
Patrick O'brien 2f9c936c6a Added inflection library, fixed all templates
* Added inflection to all templates
* Fixed broken template code (for the most part)
2016-03-18 21:26:48 +10:00

16 lines
624 B
Smarty

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