shad-go/lectures/07-sql/resources/rows.go
2020-04-09 16:03:44 +03:00

24 lines
369 B
Go

package resources
import (
"context"
"database/sql"
"log"
)
func RowsExhaust(ctx context.Context, db *sql.DB) {
rows, err := db.QueryContext(ctx, "SELECT id, name FROM users")
if err != nil {
log.Fatal(err)
}
if rows.Next() {
var id int
var name string
if err := rows.Scan(&id, &name); err != nil {
log.Fatal(err)
}
log.Println(id, name)
}
}