“In” clause in anorm?

前端 未结 7 822
轮回少年
轮回少年 2020-12-30 23:53

It seems no easy way to use \"in\" clause in anorm:

val ids = List(\"111\", \"222\", \"333\")
val users = SQL(\"select * from users where id in ({ids})\").on         


        
相关标签:
7条回答
  • 2020-12-31 00:15

    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.

    In clause with Anorm

    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)
    
    0 讨论(0)
提交回复
热议问题