I’m a golang begginer I really like the language but I can’t figure out why this refuses to work and promps me that there is no lastInstertedId. I’m using the sqlx package I also tried experimenting with the default sql one and I got pretty much the same error
type User struct {
ID int `db:"id" json:"id"`
Name string `db:"name" json:"name"`
Hash string `db:"hash" json:"-"`
}
–
func (u *User) Create() (int, error) {
res, err := db.NamedExec("insert into users (name, hash) values (:name, :hash) RETURNING users.id", u)
if err != nil {
return 0, err
}
lastID, err := res.LastInsertId()
if err != nil {
return 0, err
}
return int(lastID), nil
}
I run it as following
var me m.User
me.Name = "ayyllxdamo"
me.Hash = "adsa$axdxsdax"
ID, err := me.Create()
if err != nil {
panic(err.Error())
}
the user does get inserted.
when I run the query (manually) on the database I do get a table with an id column back.
so what could be the issue?