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

19 lines
355 B
Go

rows, err := db.QueryContext(ctx, "SELECT id, name FROM users WHERE id = $1", 1)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var id int
var name string
if err := rows.Scan(&id, &name); err != nil {
log.Fatal(err)
}
log.Println(id, name)
}
if err = rows.Err(); err != nil {
log.Fatal(err)
}