【发布时间】:2014-03-03 17:28:12
【问题描述】:
我正在尝试创建一个 findBy 方法,该方法采用键和值来搜索表。由于某种原因,以下内容没有找到任何东西:
def findBy(key: String, value: String): Option[Authentication] = DB.withConnection { implicit connection =>
SQL("select * from authentications where {key}='{value}' limit 1")
.on("key" -> key, "value" -> value).as(authentication.singleOpt)
}
但是当我只使用加号时,它确实如此。我不介意以这种方式保留它,但能够使用on 有好处
def findBy(key: String, value: String): Option[Authentication] = DB.withConnection { implicit connection =>
SQL("select * from authentications where " + key + "='" + value + "' limit 1")
.as(authentication.singleOpt)
}
示例查询:Authentication.findBy("email", "test@example.com")
【问题讨论】:
标签: sql scala playframework-2.0 anorm