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

19 lines
365 B
Go

stmt, err := db.PrepareContext(ctx, "SELECT name FROM users WHERE id = $1")
if err != nil {
log.Fatal(err)
}
defer stmt.Close()
for i := 1; ; i++ {
row, err := stmt.QueryRowContext(ctx, i)
if err != nil {
log.Fatal(err)
}
var name string
if err = row.Scan(&name); err != nil {
log.Fatal(err)
}
log.Println(name)
}