[英]I can't make a simple example of Scala Play db work
Firstly, I've never worked with a database in Scala Play Framework. 首先,我从未在Scala Play Framework中使用数据库。 I did a research and found that the only way(?) to work with it is using a plain SQL.
我进行了研究,发现使用它的唯一方法是使用普通SQL。 Is that so?
是这样吗? I wonder, isn't there a way to do that the same way I can do that in RoR using models?
我想知道,难道没有一种方法可以像我在使用模型的RoR中那样做吗? At least, I found a plenty of examples showing, even encouraging working with plain SQL.
至少,我发现了很多示例,甚至鼓励使用纯SQL。
Secondly, I can't compile the code from the official documentation: 其次,我无法从官方文档中编译代码:
import play.api.db._
import play.api.Play.current
val result:Boolean = SQL("Select 1").execute() //SQL is not found
Also, where is SQL
located? 另外,
SQL
在哪里?
Importing anorm._
should fix the issue. 导入
anorm._
应该可以解决此问题。
SQL
is located in the package object anorm
SQL
位于包对象anorm
Btw, SQL
does not work without the sql connection, so wrap it like this: 顺便说一句,
SQL
不会没有SQL连接工作,所以把它包这样的:
DB.withConnection { implicit c =>
SQL("select 1").execute()
}
Have you added the sql dependency to your project as described in the docs? 您是否按照文档中所述将sql依赖项添加到项目中?
http://www.playframework.com/documentation/2.2.x/ScalaDatabase http://www.playframework.com/documentation/2.2.x/ScalaDatabase
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.