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

RunInTransaction should be part of the orm.DB interface #1289

Closed
ericgorlin opened this issue Jul 10, 2019 · 3 comments · Fixed by #1857
Closed

RunInTransaction should be part of the orm.DB interface #1289

ericgorlin opened this issue Jul 10, 2019 · 3 comments · Fixed by #1857
Labels

Comments

@ericgorlin
Copy link

ericgorlin commented Jul 10, 2019

Both *pg.Tx and *pg.Db have access to this function, but it's not in their shared interface.
I'm using this as a workaround:

var err error
switch txOrDB := db.(type) {
case *pg.Tx:
	err = txOrDB.RunInTransaction(f)
case *pg.DB:
	err = txOrDB.RunInTransaction(f)
}
if err != nil {
	return nil, err
}
@vmihailenco
Copy link
Member

RunInTransaction refers to pg.Tx which can't be accessed in orm package because of the circular dependency. Perhaps go-pg should have separate interface like pg.DBer.

@ericgorlin
Copy link
Author

I'm guessing there's a good reason, but why does orm.DB need to live in orm rather than pg?

@ericgorlin
Copy link
Author

ericgorlin commented Jul 10, 2019

And why do we need separate orm and pg packages if they're going to cause circular dependencies like this due to interconnectedness?

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

Successfully merging a pull request may close this issue.

2 participants