One
Execute a query and return a type representing a single row
Similar to QueryRowContext
, but works directly on a bob.Query
object.
This function is a wraper around scan.One
.
type userObj struct {
ID int
Name string
}
ctx := context.Background()
db, err := bob.Open("postgres", "...")
if err != nil {
// ...
}
q := psql.Select(...)
// user is of type userObj{}
user, err := bob.One(ctx, db, q, scan.StructMapper[userObj]())
if err != nil {
// ...
}