b43f9c63d8
* Database driver config & flag complete * Table flag complete, will use all tables if non specified
20 lines
483 B
Smarty
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
|
|
}
|