shad-go/lectures/07-sql/nulls/rows.go

29 lines
401 B
Go
Raw Normal View History

2020-04-09 11:15:34 +00:00
package nulls
import (
"context"
"database/sql"
"log"
)
func Results(ctx context.Context, db *sql.DB) {
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 s sql.NullString
if err := rows.Scan(&s); err != nil {
log.Fatal(err)
}
if s.Valid {
//
} else {
//
}
}
2020-04-08 19:20:23 +00:00
}