sqlboiler/templates/select.tpl
Patrick O'brien b43f9c63d8 Struct generation complete, pipes to stdout
* Database driver config & flag complete
* Table flag complete, will use all tables if non specified
2016-02-23 18:27:32 +10:00

20 lines
483 B
Smarty

func Insert{{makeGoColName $tableName}}(o *{{makeGoColName $tableName}}, db *sqlx.DB) (int, error) {
if o == nil {
return 0, errors.New("No {{objName}} provided for insertion")
}
var rowID int
err := db.QueryRow(
`INSERT INTO {{tableName}}
({{makeGoInsertParamNames tableData}})
VALUES({{makeGoInsertParamFlags tableData}})
RETURNING id`
)
if err != nil {
return 0, fmt.Errorf("Unable to insert {{objName}}: %s", err)
}
return rowID, nil
}