Reputation: 9559
Hi I just update and run the the simple slick Table and want to inquire it.
import scala.slick.driver.PostgresDriver.simple._
import scala.slick.lifted.TableQuery
class Coffees(tag: Tag) extends Table[(String, Double)](tag, "COFFEES") {
def name = column[String]("COF_NAME", O.PrimaryKey)
def price = column[Double]("PRICE")
def * = (name, price)
}
val coffees = TableQuery[Coffees];
The error is:
[error] C:\testprojects\slickplay\app\model\Coffee.scala:11: expected class or o bject definition
[error] val coffees = TableQuery[Coffees];
The TableQuery[Coffees] do not return objects???how to fix it.
Upvotes: 3
Views: 532
Reputation: 2607
Or you can put all things in side trait:
import scala.slick.driver.PostgresDriver.simple._
trait DomainComponent{
class Coffees(tag: Tag) extends Table[(String, Double)](tag, "COFFEES") {
def name = column[String]("COF_NAME", O.PrimaryKey)
def price = column[Double]("PRICE")
def * = (name, price)
}
val coffees = TableQuery[Coffees];
}
Upvotes: 0
Reputation: 1452
You can't have a val outside of a class or object definition.
Try
object DatabaseContext {
val coffees = TableQuery[Coffees]
}
Upvotes: 1