Export (Transaction).tx *sqlx.Tx field #28
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR exports the
(Transaction).tx *sqlx.Tx
field.We use an internal fork of modl at @sourcegraph with this field exported. It makes it easier to add additional functionality to
SqlExecutor
that makes use ofsqlx
anddatabase/sql
methods/helpers. Here 2 examples from our codebase where exporting this field has been necessary/helpful. I'm just mentioning these because this is essentially an API design decision and real world use cases are often helpful to me in these situations.sqlx.Tx
(and calls.Prepare
on it), but internally all of our DB handles aremodl.SqlExecutor
:In order to be able to call
Copy
on amodl.SqlExecutor
or*modl.Transaction
, thetx
field must be exported. Then we can call, e.g.,db.Copy(dbh.(*modl.Transaction).Tx, "mytable", data)
.modl.SqlExecutor
as an argument and wants to be able to callQueryRow
on the DBMap or Transaction:The
tx
field must be exported in order to be able to use sqlx'sQueryRow
on a*modl.Transaction
. Note that the analogousDbx
field onDbMap
is exported, so it would seem consistent forTx
to also be exported.