Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create dynamic SQL with anorm

i do not want to delete and reinsert every row, so I have used the following to try to use multiple rows with anorm:

SQL("""
            delete from PERSON_ROLES 
            WHERE person_id = {userId}
            and role_id not in ({rolescommastring})
            )
            """).on('userId -> userId,
                    'rolescommastring -> rolescommastring).execute()

The above yields a string that it doesn't like and i get :

c.j.b.PreparedStatementHandle - delete from PERSON_ROLES WHERE person_id = 1460 and role_id not in ( '1, 3, 8, 9' )

can i create dynamic sql with anorm?

like image 655
mbrambley Avatar asked May 16 '26 01:05

mbrambley


1 Answers

Since Anorm 2.3, multi-value parameters are supported.

SQL("""
        delete from PERSON_ROLES 
        WHERE person_id = {userId}
        and   role_id not in ({rolescommastring})
        )
        """).on('userId -> userId,
                'rolescommastring -> Seq("id1", "id2", "id3")).execute()

There are more similar examples at https://www.playframework.com/documentation/2.3.x/ScalaAnorm

like image 86
cchantep Avatar answered May 17 '26 15:05

cchantep