Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top