I'm trying out scala and quill (getquill.io). This minimal example below fails to compile. Why is that? It only defines one single class. I suspect I need to mark the class up somehow for quill to be able to parse it, but I don't know how. I got attracted to quill over slick because I don't have to mark up case classes, they're supposed to just work, is that correct?

package dbquerytest

import io.getquill._
/*in a real life you would rather pass execution context as
  a method or constructor argument, but we're just playing*/
import scala.concurrent.ExecutionContext.Implicits.global

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

case class Intake( id:Int, path:String, stage:Int) // , timestamp: Instant

// running/using junit test:https://alvinalexander.com/scala/how-to-use-junit-testing-with-scala
class MysqlLocalDbTest  {
  @Test
  def testIntake={
    val ctx = new MysqlAsyncContext(SnakeCase, "testdb")
    import ctx._
    val intakes = quote { query[Intake].map(_.id )}
    ctx.run(intakes).map(_.headOption)

    assertEquals(0,0)
  }
}

Compilation fails at at io.getquill.quotation.Parsing.

1 Answers

4
MelvinWM On Best Solutions

First off, I can see that you are using JUnit 5 in the code snippet, but there seems to be some issues reg. using JUnit 5 with Scala and sbt: https://github.com/sbt/junit-interface/issues/75 . Alternatives include using JUnit 4 or one of the Scala-specific test libraries like ScalaTest or specs2 (ScalaCheck also bears mention, though I have typically only used it in combination with ScalaTest or specs2).

Second off, I do not know which build tool you are using, and if you have all the relevant dependencies in it, which may be the cause of the compilation errors. If you are using sbt ( https://www.scala-sbt.org/ ), which I believe is the most common build tool when developing with Scala, one possible example for how it may look for your example is this (using JUnit 4):

build.sbt:

import Dependencies._

ThisBuild / scalaVersion     := "2.12.8"
ThisBuild / version          := "0.1.0-SNAPSHOT"
ThisBuild / organization     := "com.example"
ThisBuild / organizationName := "example"

lazy val root = (project in file("."))
  .settings(
    name := "quilltesting",
    libraryDependencies ++= Seq(
      "mysql" % "mysql-connector-java" % "8.0.15",

      "io.getquill" %% "quill-jdbc" % "3.1.0",
      "io.getquill" %% "quill-async-mysql" % "3.1.0",

      // JUnit 4.
      "com.novocode" % "junit-interface" % "0.11" % Test
    )
  )

To generate a quick project from scratch to test with that uses sbt, create a new folder somewhere, path into it from the command-line and run sbt new sbt/scala-seed.g8. Then go into the folder, and run sbt. After that, run test.

I have changed your example to use JUnit 4, and it seems to compile and run:

package dbquerytest

import io.getquill._

/*in a real life you would rather pass execution context as
  a method or constructor argument, but we're just playing*/
import scala.concurrent.ExecutionContext.Implicits.global

import org.junit.Test
import junit.framework.TestCase
import org.junit.Assert._

case class Intake( id:Int, path:String, stage:Int)

// running/using junit test:https://alvinalexander.com/scala/how-to-use-junit-testing-with-scala
class MysqlLocalDbTest  {
  @Test
  def testIntake = {
    val ctx = new MysqlAsyncContext(SnakeCase, "testdb")
    import ctx._
    val intakes = quote { query[Intake].map(_.id )}
    ctx.run(intakes).map(_.headOption)

    assertEquals(0,0)
  }
}

If you want to try out some other examples, there is also https://scastie.scala-lang.org/QwOewNEiR3mFlKIM7v900A , as linked to in https://getquill.io/#quotation-introduction .