shad-go/lectures/07-sql/query/queryrow.go
2020-04-08 22:20:23 +03:00

13 lines
276 B
Go

var id int
var name string
err = db.QueryRowContext(ctx, "SELECT id, name FROM users WHERE id = $1", 1).Scan(&id, &name);
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
log.Println("nothing found")
return
}
log.Fatal(err)
}
log.Println(name)