sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Missing NamedQueryContext on *sqlx.Tx

Open samjohnduke opened this issue 7 years ago • 12 comments

Hi,

I'm not a prolific contributor, but I found this method to be missing on the transaction struct. I could just use a prepare query yes, but for consistency i think i should be there. I will create a quick pull request to fix.

Sam

samjohnduke avatar Sep 03 '18 22:09 samjohnduke

Also curious about this one, has it been removed for a reason?

mminklet avatar May 07 '19 06:05 mminklet

There have been 3 attempts at PRs for this change:

https://github.com/jmoiron/sqlx/pull/348 https://github.com/jmoiron/sqlx/pull/373 https://github.com/jmoiron/sqlx/pull/448

This repository still seems to be active, with recent commits, so it's not clear what is holding this back.

Each of the above PRs lacks any unit tests, but those should be easily implemented?

dackroyd avatar May 08 '19 01:05 dackroyd

I'm also interested in this.

johnmaguire avatar Sep 08 '21 21:09 johnmaguire

I'm pretty sure many people who actively use the package are interested.

@jmoiron is there anything that can be\should be done for this to be part of the package?

konart avatar Sep 14 '21 13:09 konart

I was creating an interface in my application so I can reuse the same code for db interaction with and without transactions and that's when I realized NamedQueryContext is missing in sqlx.Tx. Any particular reason why this method is missing?

josnidhin avatar Nov 23 '21 04:11 josnidhin

Six PRs have been made for this issue that I could find right now:

https://github.com/jmoiron/sqlx/search?q=NamedQueryContext+is%3Apr&type=issues

Also, this is the second highest voted issue out of 240 open ones:

https://github.com/jmoiron/sqlx/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc

@jmoiron do you think you could do one of:

  • If you can't / won't maintain this project any more:
    • Find one or more new maintainers. Maybe ask some of the biggest-contributors-except-yourself if they want in?
    • Or, put a note at the top of README.md that the project won't be maintained any more and archive it
  • Look into one of the above PRs and have one of them merged

Either way, you built something useful, thanks!

walles avatar Dec 22 '21 11:12 walles

Just in case someone hasn't figured this out yet: it is possible to do sqlx.NamedQueryContext(ctx, tx, query, arg). tx must implement sqlx.ExtContext (allowing your caller to accept either a tx or DB connection itself.)

johnmaguire avatar Jan 08 '22 02:01 johnmaguire

sqlx.NamedQueryContext(ctx, tx, query, arg) with postgres resulted in question marks in the query instead of the postgres positional characters like $1, $2..

I see in the documentation it's mentioned in some places that actually these arguments become ? indeed, so not sure if this is an incompatibility with postgres or if there is something I missed.

sakishrist avatar Nov 04 '22 13:11 sakishrist

+1 to wanting this

s-mang avatar Dec 20 '22 19:12 s-mang

@sakishrist Reading sqlx.NamedQueryContext, it seems to choose the bind mode based on the driver name. If you are using a custom postgres driver, that may be your issue.

johnmaguire avatar Dec 21 '22 06:12 johnmaguire

+1 to wanting this! This wasn't solved in the meantime right?

nd291195 avatar Apr 22 '24 09:04 nd291195