1
votes

I made a simple Slick project as documented in Slick 3.1.1 documentation

First, I added Slick dependency in build.sbt

Second, I imported as below to use H2 database

import slick.driver.H2Driver.api._
import scala.concurrent.ExecutionContext.Implicits.global

Third, I made a db connection

val db = Database.forURL("jdbc:h2:mem:test1;DB_CLOSE_DELAY=-1", driver="org.h2.Driver")

And then I made a schema

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)
}

And populated some database

records += (None, "name1", "target1", new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), 4, 8, 0.5, false)

I refered official HelloSlick template(https://github.com/typesafehub/activator-hello-slick/blob/master/src/main/scala/HelloSlick.scala) for this

But When I tried to compile, I got 19 errors

First error is : object slick is not a member of package scala import scala.slick.driver.H2Driver._

I thought very strange because it is needed to be imported

Other errors are not found: value Database,
not found: value driver,
not found: type Table,
not found: type Tag,
not found: value coumn,
value PrimaryKey is not a member of Int,
not found: value column.... and many of these not found: value column

I don't have any clue about this

If anyone knows, please help me

1
Replace 'O' to '0' in '0.PrimaryKey' and replace 'O.AutoInc' to 'O AutoIn' - Majid Hosseini

1 Answers

0
votes

The master branch of the Hello Slick template uses Slick 2.0.2, many of the package members have changed.

Use the slick-3.1 branch (https://github.com/typesafehub/activator-hello-slick/tree/slick-3.1) for Slick 3+ examples. This template uses Slick 3.1.0-RC2, you can upgrade to Slick 3.1.1.

A known issue https://github.com/typesafehub/activator/issues/1036 for the play-fork-run.sbt file. You can comment or delete it.