【发布时间】:2016-04-02 01:24:26
【问题描述】:
我制作了一个简单的 Slick 项目,如 Slick 3.1.1 文档中所述
首先,我在 build.sbt 中添加了 Slick 依赖
其次,我导入如下使用H2数据库
import slick.driver.H2Driver.api._
import scala.concurrent.ExecutionContext.Implicits.global
第三,我做了一个db连接
val db = Database.forURL("jdbc:h2:mem:test1;DB_CLOSE_DELAY=-1", driver="org.h2.Driver")
然后我做了一个架构
class Records(tag: Tag) extends Table[(Int, String, String, Date, Date, Date, Long, Long, Double, Boolean)](tag, "RECORDS"){
def id = column[Int]("ID", 0.PrimaryKey, O AutoIn) // This is the primary key column
def name = column[String]("NAME")
def target = column[String]("TARGET")
def timeStamp = column[Date]("TIME_STAMP")
def startTime = column[Date]("START_TIME")
def endTime = column[Date]("END_TIME")
def readBytes = column[Long]("READ_BYTES")
def writeBytes = column[Long]("WRITE_BYTES")
def usage = column[Double]("USAGE")
def useDelta = column[Boolean]("USE_DELTA")
def * = (id.?, name, target, timeStamp, startTime, endTime, readBytes, writeBytes, usage, useDelta)
}
并填充了一些数据库
records += (None, "name1", "target1", new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), 4, 8, 0.5, false)
我为此参考了官方的 HelloSlick 模板(https://github.com/typesafehub/activator-hello-slick/blob/master/src/main/scala/HelloSlick.scala)
但是当我尝试编译时,我得到了 19 个错误
第一个错误是:对象 slick 不是包 scala 的成员 导入 scala.slick.driver.H2Driver._
我觉得很奇怪,因为需要导入
其他错误是
未找到:值数据库,
未找到:价值驱动程序,
未找到:类型表,
未找到:键入标记,
未找到:值 coumn,
值 PrimaryKey 不是 Int 的成员,
未找到:值列....其中许多未找到:值列
我对此一无所知
如果有人知道,请帮助我
【问题讨论】:
-
将 '0.PrimaryKey' 中的 'O' 替换为 '0' 并将 'O.AutoInc' 替换为 'O AutoIn'