jmoiron / sqlx

general purpose extensions to golang's database/sql
http://jmoiron.github.io/sqlx/
MIT License
16.07k stars 1.08k forks source link

Missing NamedQueryContext on *sqlx.Tx #447

Open samjohnduke opened 6 years ago

samjohnduke commented 6 years ago

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

mminklet commented 5 years ago

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

dackroyd commented 5 years ago

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?

johnmaguire commented 3 years ago

I'm also interested in this.

konart commented 3 years ago

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?

josnidhin commented 2 years ago

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?

walles commented 2 years ago

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:

Either way, you built something useful, thanks!

johnmaguire commented 2 years ago

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.)

sakishrist commented 1 year ago

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.

s-mang commented 1 year ago

+1 to wanting this

johnmaguire commented 1 year ago

@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.

nd291195 commented 5 months ago

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