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

removed simple+incorrect IN expansion #524

Closed

Conversation

truesilver92
Copy link

in sql_builder.go line 91 already calls out to sqlx.In to do an
expansion that supports multiple IN statements. The removed section
duplicated behavior and has a bug between the regex selection and what
strings.Replace replaces (selects \(\s*\?\s*\) but only replaces
\(\?\)

in `sql_builder.go` line 91 already calls out to `sqlx.In` to do an
expansion that supports multiple IN statements. The removed section
duplicated behavior and has a bug between the regex selection and what
`strings.Replace` replaces (selects `\(\s*\?\s*\)` but only replaces
`\(\?\)`
@truesilver92 truesilver92 requested a review from a team as a code owner March 4, 2020 22:46
@truesilver92 truesilver92 reopened this Mar 4, 2020
@truesilver92
Copy link
Author

truesilver92 commented Mar 4, 2020

This constitutes a breaking change. I think it is worth it, but I am
not sure if you want to have a deprication time that warns about the
change in behavior, and wait until at least next major release.

There is a work around for people that want the behavior that
RawQuery and everything else currently has. Call sqlx.In passing
your sql and arguments to do the expansion, then pass the resulting
sql and arguments to Where

you can use compile's usage as an example https://github.com/gobuffalo/pop/blob/master/sql_builder.go#L91

@sio4 sio4 self-assigned this Sep 18, 2022
@sio4 sio4 added this to the v6.0.7 milestone Sep 18, 2022
@sio4 sio4 added the s: triage Some tests need to be run to confirm the issue label Sep 18, 2022
@sio4
Copy link
Member

sio4 commented Sep 18, 2022

Hello @truesilver92, thanks for your contribution!

The description of the PR looks nice but the patch is somewhat odd to me. I will take care of the code tomorrow and will update the result. Also, I am not sure if you want to work on this PR now. Please let me know if you have interest in it, otherwise, I will take it over and will fix it.

@sio4 sio4 mentioned this pull request Sep 20, 2022
30 tasks
@sio4
Copy link
Member

sio4 commented Sep 23, 2022

Although the direction of supporting slice as an argument for IN could be nice (as introduced by [4] for the first time), this PR cannot be merged for several reasons:

in sql_builder.go line 91 already calls out to sqlx.In to do an expansion that supports multiple IN statements. The removed section duplicated behavior

Roughly, they look the same, but we need to see them in a logical context. The "removed section" basically do a similar job, but the target statement is totally different. In the SQL Builder, the function takes a whole generated SQL statement so the statement could have multiple ?, so matching them with multiple arguments is not easy (a single value or slice per each ? could help this though). Previously we had a related issue [2] and PR [3] to fix it, and this change will bring that issue again.

and has a bug between the regex selection and what strings.Replace replaces (selects (\s*?\s*) but only replaces
(?)

This is a valid point, I would like to file a new PR for this to fix this bug.

This constitutes a breaking change. I think it is worth it, but I am not sure if you want to have a deprication time that warns about the change in behavior, and wait until at least next major release.

Yes, this could be a big breaking change since .Where() could be one of the most popular methods for users, and they mostly use it with variadic arguments. Also, if we change this way completely, there are more things to be fixed with it to make it works.

There is a work around for people that want the behavior that RawQuery and everything else currently has. Call sqlx.In passing your sql and arguments to do the expansion, then pass the resulting sql and arguments to Where

Since the method still working smoothly (except for the regex bug), it could be fine if we do not change the current behavior of parsing the statement one more time here.

Anyway, I would like to keep this idea for the next major release.

Some references:

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.

2 participants