My goal is to fetch the newly added tsk_id from the INSERT INTO
It seems that the headers from MustExec not is updated or converted correctly.
Any clue welcome!
I’m not familiar with sqlx, but in plain ol’ database/sql, you use db.Query or db.QueryRow to execute your insert and then the RETURNING tsk_id part of the query is retrieved as a scalar value in that row.
Thanks for pointing me in the right direction. This seems to work.
func Create(w http.ResponseWriter, r *http.Request) { // simplified
data = new(query, val)
json.NewEncoder(w).Encode(data)
}
// add new record
func new(query string, val string) interface{} {
var id int
err := db.QueryRowx(query, val).Scan(&id)
if err != nil {
return nil
}
return (id)
}