Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScanRows in *bun.Tx #586

Open
sdzyba opened this issue Jun 20, 2022 · 4 comments
Open

ScanRows in *bun.Tx #586

sdzyba opened this issue Jun 20, 2022 · 4 comments
Labels
question Further information is requested stale

Comments

@sdzyba
Copy link
Contributor

sdzyba commented Jun 20, 2022

Hello @vmihailenco

From docs I understand that it's possible to execute a custom query and scan the results into a custom model.
But that's only possible to do on *bun.DB, but not on *bun.Tx because although Tx has Query() method, it doesn't have ScanRows().

Is there a specific reason for that? Or it's actually possible to extend *bun.Tx with ScanRows() method and also add this method to bun.IDB?

@vmihailenco
Copy link
Member

It is possible, but ScanRows does not need access to the *bun.Tx - rows already read all data from the tx.

You can do something like this:

rows, err := tx.Query(...)
if err != nil {
    panic(err)
}

err = db.ScanRows(ctx, rows, dest)

We can add tx.DB() and conn.DB() if that helps.

@vmihailenco vmihailenco added the question Further information is requested label Jun 22, 2022
@sdzyba
Copy link
Contributor Author

sdzyba commented Jun 22, 2022

Thanks for the answer.

The issue is that we try to abstract away both *bun.Tx and *bun.DB usage under bun.IDB interface because we want to operate with the interface on the application level.

We're switching from go-pg to Bun right now and it is possible to execute .Query() both on go-pg's pg.DBI and bun's bun.IDB, but the difference is that the former accepts model in it's arguments, while the latter expects you to "parse" the rows through ScanRows which is not a part of the interface.

So the only solution for our approach is to have this interface extended.
Yes, we could define our own extended interface with ScanRows() added, but generally I'd expect that both Bun and go-pg are having similar interfaces (in terms of functionality, not semantics) out of the box.

@jeffreydwalter
Copy link
Contributor

I have the same issue. There are many areas where the API differences between go-pg and bun make it impossible to do things that were possible in go-pg. Apply() is another place: #888

Copy link

github-actions bot commented Nov 7, 2024

This issue has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this issue will be closed.

@github-actions github-actions bot added the stale label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested stale
Projects
None yet
Development

No branches or pull requests

3 participants