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

Add sqlc.slice() to support IN clauses in MySQL (#695) #1816

Merged
merged 1 commit into from
Apr 7, 2023

Conversation

Jille
Copy link
Contributor

@Jille Jille commented Aug 23, 2022

This feature allows passing in a slice to an IN clause. Adding the new function sqlc.slice() as opposed to overloading the parsing of "IN (?)" was chosen to guarantee backwards compatibility.

SELECT * FROM tab WHERE col IN (sqlc.slice("go_param_name"))

This commit is based on #1312 by
Paul Cameron. I just rebased and did some cleanup.

Co-authored-by: Paul Cameron cameronpm@gmail.com

@Jille Jille marked this pull request as draft August 23, 2022 08:39
@Jille Jille force-pushed the sqlc.slice branch 2 times, most recently from 5515aa5 to 8ca1ff1 Compare August 23, 2022 09:23
@Jille Jille marked this pull request as ready for review August 23, 2022 09:25
@Jille
Copy link
Contributor Author

Jille commented Aug 23, 2022

I'm not sure why the tests fail. It complains about codegen.json mismatching and says there's thousands of {mis,}matching lines, but the file is only ~500 lines. I suspect something regenerates it, but I failed to find the culprit.

@derekperkins
Copy link

Does this have a path towards supporting multiple IN args?
e.g. (col1, col2, ...) IN ((?,?,...), (?,?,...))

@kyleconroy kyleconroy self-requested a review September 1, 2022 01:53
@Rhymond
Copy link

Rhymond commented Oct 21, 2022

what's the status of this PR? What's missing?

@Jille
Copy link
Contributor Author

Jille commented Oct 21, 2022

I'm waiting for @kyleconroy to review. I'm hoping he can give me a pointer for the failing test.

Does this have a path towards supporting multiple IN args?

That should be doable to add on top of this PR.

@Rhymond
Copy link

Rhymond commented Oct 23, 2022

I'm waiting for @kyleconroy to review. I'm hoping he can give me a pointer for the failing test.

Does this have a path towards supporting multiple IN args?

That should be doable to add on top of this PR.

I'm looking at your code and thinking would it be better to do what sqlx did for for queries with IN (please check https://jmoiron.github.io/sqlx/ "in Queries"). In that way you would keep original query as parameter and you wouldn't need to use custom placeholder in your case /*SLICE:ids*/?
You could replace all sqlc.slice() funcs with a question mark (same as sqlc.arg does) and then only if sqlc.slice() exists call sqlx.in in the generated function to replace query question marks and prepare argument list. What do you think?

@Jille
Copy link
Contributor Author

Jille commented Jan 2, 2023

@Rhymond apologies for the late reply

Your proposal consists of two parts: a) Keep using ? as the place holder, and b) Factor out the generated code and call a library instead.

a) I don't mind much which way to go. /*SLICE:ids*/ was easier to work with in fewer lines of generated code.
b) We currently don't ever import github.com/kyleconroy/sqlc, I'd like Kyle's opinion on it before going that direction.

I'd propose to first get this in, and we can easily refactor later.

@Jille
Copy link
Contributor Author

Jille commented Jan 2, 2023

@kyleconroy this is ready to be merged

I've rebased and the test failures magically went away. Maybe I was based on a bad commit before ¯\(ツ)

@ajaxify
Copy link

ajaxify commented Jan 8, 2023

I've tested this branch out in a new project and found it works as expected so far. Would love to see this merged! Thank you @Jille for the work!

@roccoblues
Copy link
Contributor

Hi @kyleconroy we're sponsoring this project and would really love to see this feature. It's also been requested a lot (#695) by other people.

Is there anything missing that prevents this from getting merged? Happy to help as well.

Thanks for your work!

sosolyht added a commit to sosolyht/ddd-healthRoutine that referenced this pull request Feb 10, 2023
TODO: 요청당 쿼리 계속 날라감
sqlc sqlc-dev/sqlc#1816

머지되면 리팩토링
@johnwayne19860314
Copy link

appreciated if this feature get supported as soon as possible

@uasouz
Copy link

uasouz commented Feb 23, 2023

this feature will be merged on the next release?

@Rhymond
Copy link

Rhymond commented Mar 6, 2023

How can we move this forward? What's missing? I'm keen to help

@ogugu9
Copy link

ogugu9 commented Mar 14, 2023

I'm looking forward this feature!

@koolay
Copy link

koolay commented Apr 2, 2023

@kyleconroy

This feature (currently MySQL-specific) allows passing in a slice to an
IN clause. Adding the new function sqlc.slice() as opposed to overloading
the parsing of "IN (?)" was chosen to guarantee backwards compatibility.

   SELECT * FROM tab WHERE col IN (sqlc.slice("go_param_name"))

This commit is based on sqlc-dev#1312 by
Paul Cameron. I just rebased and did some cleanup.

Co-authored-by: Paul Cameron <cameronpm@gmail.com>
@Jille
Copy link
Contributor Author

Jille commented Apr 3, 2023

I've rebased to main.

@kyleconroy kyleconroy merged commit a8477b8 into sqlc-dev:main Apr 7, 2023
5 checks passed
@ecornelisse
Copy link

would it be possible to create a new release already so this important feature included?

@Jille Jille deleted the sqlc.slice branch February 26, 2024 21:47
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

Successfully merging this pull request may close these issues.

None yet