Execute and assign the result of a SQL query #592
Unanswered
adriendumont
asked this question in
Q&A
Replies: 1 comment 2 replies
-
I believe it should be: rows, err := db.Query(query, userId)
if err == nil {
db.ScanRows(&recommendations)
} But we probably should also support something like this: err := db.Raw(query, args).Scan(ctx, &dest) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there!
I'm currently migrating a project from
go-pg
tobun
and I'm having a bit of difficulties migrating the following SQL query:with
go-pg
I'd have something like_, err := db.QueryOne(pg.Scan(&recommendations), query, userId)
and the data would be assigned to a zero length slice of types:With
bun
, I can't figure out how to makeScan
properly assign the values. This is the code:Now, I'm also trying with QueryRow (this particular query should return either no rows or only 1 row but in this case I'm getting the following error:
sql: Scan error on column index 0, name "agg_scores": unsupported Scan, storing driver.Value type []uint8 into type *[]Recommendation
So, my question would be how do i go about implementing a similar thing as in
go-pg
? Is it possible out of the box?Beta Was this translation helpful? Give feedback.
All reactions