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

Support for beginning a transaction inside boiler generated package #88

Closed
eduacostam opened this issue Jan 9, 2017 · 3 comments
Closed

Comments

@eduacostam
Copy link

This is only a proposal, maybe it needs some discussion.

The idea is that if we use boiler.SetDB(db) method in order to be able to use the G variants of the models, and avoid having to pass around a sql.DB instance, then there's no way to create a transaction inside a function of a struct that does not have the db instance in scope.

It might be nice to have a method in the models package func Begin() (*sql.Tx, errors) that uses the db instance passed into the SetDB method for creating a transaction and returning it, this way we can use transactions (for example when working with relationships) but still avoid having our structs have the need of the DB instance.

@eduacostam
Copy link
Author

Nevermind, I've just found that there is indeed a Begin() method that returns a Transactor... I don't know how I missed it before...

@aarondl
Copy link
Member

aarondl commented Jan 10, 2017

Will document better.

@aarondl aarondl reopened this Jan 10, 2017
@eduacostam
Copy link
Author

That's awesome @aarondl, much clearer now haha
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants