使用UUID Anorm 2.3列表进行自定义隐式转换

时间:2016-12-27 16:37:17

标签: postgresql scala anorm

我需要在此代码示例中为UUID列表定义anorm隐式转换:

 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.*)
  }
}

我从表单中获取UUIDS作为字符串。 我知道我需要进行隐式转换,但我无法找到如何做到这一点(谷歌搜索了许多东西,但我无法得到它......)

我已经将UUID的隐式类型转换转换为运行良好的语句:

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

我需要的是将List [String]或List [UUID]隐式转换为statment ...

如果您有关于toStatement []和自定义anorm隐式转换的详细解释示例的链接,我将非常感激

提前谢谢!

0 个答案:

没有答案
相关问题