We can write sqls like following in play2's anorm:

def findById(id: String): Option[Link] = DB.withConnection {implicit connection =>
  SQL("select * from links where id={id}").on('id -> id).as(simple.singleOpt)
}

It uses {xxx} format as the placeholder, and the specify a map 'id->id. Is there anyway to use ? as the placeholder as we do in play1?

I hope I can write it like:

def findById(id:String): Option[Link] = DB.withConnection {implicit connection =>
  SQL("select * from links where id=?").on(id).as(simple.singleOpt)
}

This format is very useful sometimes.

有帮助吗?

解决方案

No, currently Anorm uses the Scala symbols for the mapping and you can't use '?'.

This may change in the future, but it is not possible right now.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top