I have searched about 2 emails regarding support for anorm's "in" sql
clause. But there seems to be no real conclusion the thread.
How can I make sql "in" clause work?
val listOfBars = List(1, 2, 3)
SQL("""select * from foo where bar in
({listOfBars})""").on("listOfBars" -> listOfBars)
Also it seems after 2.0 Beta Magic is not in anorm jar anymore? I was
using the jars published for anorm standalone here:
http://download.playframework.org/ivy-releases/play/anorm_2.9.1/2.0-beta/jars/
Then when I grabbed the anorm jar from a locally built Play RC-1
framework, I can seem to see Convention Magic anymore. Can someone
tell me where the Magic is now in 2.0? Thanks.
Jun
> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
--
Guillaume Bort
Was just asking about Magic as it was on 1.2.x and beta 2.0, there are
a few tables where it could be handy. However if its really out in
2.x that is also ok w/ me. I primarily picked anorm because I wanted
to do sql. I am using it for a data extract code, so direct sql seems
to be a better option in the current context.
I have also used mkString, in particular mkString("'","','","'").
However it seems to be a bit weird. Some of my code currently does a
mkString on some condition and uses ".on" on some condition. Maybe
iterable type place holders should be expanded?
Jun
> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
Nailed it! There haven't really been any more updates on this thread, but it seems to still be relevant. Because of that, and because there isn't an answer, I thought I'd throw mine in for consideration.
Anorm doesn't support 'IN' clauses. I doubt they ever will. There's nothing you can do to make them work, I even read a post where anorm specifically took out those clauses because they made Anorm feel 'like an ORM'.
It's fairly easy, however, to wrap the SqlQuery in a short class that supports the IN clause, and then convert that class into a SqlQuery when needed.
Instead of pasting the code in here, because it gets a little long, here is the link to my blog, where I've posted the code and how to use it.
Basically, when you have the code from my blog, your statements look like this:
RichSQL(""" SELECT * FROM users WHERE id IN ({userIds}) """).onList("userIds" -> userIds).toSQL.as(userParser *)(connection)
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
val userIds = List(1, 3, 5)
SQLin"select * from users where id in ($userIds)".as(userParser *)