Custom implicit conversion with lists of UUID Anorm 2.3

308 views Asked by At

i need to define anorm implicit conversion for lists of UUIDs in this code sample:

 case class users(
    name = String
 )

 val userParser: RowParser[users]= {
    get[String]("name") map {
        case name => users(name)
    }
 }

def getUsersNames():List[users] = {
   val uuids = List("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11") 

   DB.withConnection { implicit c =>
   return SQL("SELECT name FROM user WHERE uuid IN({uuids})").on( 'uuids -> uuids ).as(users.*)
  }
}

i get UUIDS as string from a form. I know that i need to do a implicit conversion but i cant find how to do it (googled many things but i can't get it ...)

i already have implicit type conversion for UUID to statement that work well:

  implicit val uuidToStatement = new ToStatement[UUID] {
    def set(s: java.sql.PreparedStatement, index: Int, aValue: UUID): Unit = s.setObject(index, aValue)
  }

all i need is implicit conversion for List[String] or List[UUID] to statment...

also if you have a link with well explained examples about toStatement[] and custom anorm implicit conversion i'll be very grateful

thanks in advance!

0

There are 0 answers