-
Notifications
You must be signed in to change notification settings - Fork 357
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
Introduce updateSetOpt
fragment (#1893)
#2126
Conversation
test("updateSetOpt for three column") { | ||
assertEquals( | ||
updateSetOpt(Fragment.const("Foo"), sqlKv, List.empty[Fragment]).map(_.query[Unit].sql), | ||
Some("UPDATE Foo SET a = ?, b = ?, c = ? ")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we currently have an empty space, if the WHERE
clause is empty. Let me know, if this should be handled differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spaces are fine :)
def updateSetOpt[F[_]: Foldable]( | ||
tableName: Fragment, | ||
columnUpdates: F[Fragment], | ||
whereAnd: F[Fragment] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks this is a good start!
In my comment what I was thinking was a fragment for the where condition, so the signature should be condition: Fragment
Usage will look like:
updateSetOpt(
fr"my_table",
...,
condition = fr"some_col > 50"
)
or a more complicated example
updateSetOpt(
fr"my_table",
...,
condition = fragments.inOpt(fr"name", nameList).getOrElse(fr"false")
)
This way the user have full control over the condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jatcwang, thanks for the clarification. I updated the signature accordingly.
I'd like to weigh in a little, if I may. It looks like the proposed Wouldn't it be better to use the
Also I'm not sure if it makes sense to include the
OR if
Note that
Therefore including the |
@satorg With these fragment helpers the general principle I'm following is that it should be hard / impossible to generate invalid SQL or (worse) SQL that lead to the wrong behaviour. Hence I support having Regarding requiring Reducible instead of Foldable, It's a matter of convenience I guess.
vs
We can have both like we do for most combinators :) RETURNING doesn't seem to be supported in MySQL so makes sense to leave that out and let people add it themselves. |
Not sure I'm completely following, sorry. AFAIK, the Moreover, I think it would be nice to have an override of def updateSet(tableName: Fragment, colUpdate1: Fragment, colUpdates: Fragment*): Fragment = ... In this case the
Agree. Although it is hard for me to imagine where the -Opt variant could be useful, but I admit there could be some.
Yeah, kinda agree too. I feel though that everything but |
@satorg Good point that with the current signature we cannot generate queries like Also @matsluni feel free to focus on addressing your immediate usecase (i.e. just implement |
Thanks @matsluni. I'm not sure why it's failing on M1 - Do you remember what sort of errors you're getting? |
@jatcwang, firstly I needed to switch to aarm64 compatible mysql image in the docker compose. I think I finally tested with |
Thanks for the info! I'll see if I can reproduce and fix it. |
I have created #2126 to track this |
This tries to solve #1893.
I hope the tests run through, as I could not successfully run all tests locally. At some point the testsuite just hanged on my Apple M1. Also, locally, I needed to switch the mysql docker image in the docker compose file to work on the M1.