zio / zio-quill

Compile-time Language Integrated Queries for Scala
https://zio.dev/zio-quill
Apache License 2.0
2.15k stars 348 forks source link

Improve the query probing error message when the context is not created in a separate compilation unit #844

Closed steffenlaursen closed 7 years ago

steffenlaursen commented 7 years ago

This template isn't a strict requirement to open issues, but please try to provide as much information as possible.

Version: (e.g. 0.4.1-SNAPSHOT) Included build.sbt: val sversion = "2.11.8"

lazy val root = (project in file(".")). settings( name := "tut-quill-1", version := "0.1",

scalaVersion := sversion,

libraryDependencies ++= Seq(
  "org.postgresql" % "postgresql" % "9.4.1208",
  "io.getquill" %% "quill-jdbc" % "1.3.0"
)

)

Module: (e.g. quill-jdbc) Not sure.

Database: (e.g. mysql) Postgresql 9.6

Expected behavior

The "with QueryProbing" should compile. Probing should work and validate to confirm/reject SQL. Removing the "with QueryProbing" makes it compile, but doesn't query the database.

Actual behavior

Compilation error with other exception: Can't load the context of type 'XAccountDao..type' for compile-time query probing. Reason: 'java.lang.ClassNotFoundException: XAccountDao.$' Hello.scala Same issue in both sbt and ScalaIDE.

Steps to reproduce the behavior

Create this source file, Hello.scala, and try to compile it: import io.getquill._

object Hello extends App { new XAccountDao }

case class XAccount(name: String, balance: Long)

class XAccountDao { // doesn't matter if it is

val ctx = new PostgresJdbcContextCamelCase with Escape with QueryProbing

import ctx._

val res = selectJohnsBalanceS res.foreach(x => println(x))

def selectJohnsBalanceS = { val s = quote { query[XAccount] } ctx.run(s) } }

If the issue can be reproduced using a mirror context, please provide a scalafiddle that reproduces it. See https://scalafiddle.io/sf/pMg4JvY/1 as an example. Remember to select the correct Quill version in the left menu.

Workaround

Haven't found any.

Database info:

CREATE DATABASE quill_demo WITH OWNER = postgres ENCODING = 'UTF8' LC_COLLATE = 'Danish_Denmark.1252' LC_CTYPE = 'Danish_Denmark.1252' TABLESPACE = pg_default CONNECTION LIMIT = -1;

SQL script for creating table: -- Table: public."XAccount"

-- DROP TABLE public."XAccount";

CREATE TABLE public."XAccount" ( name character varying(40) COLLATE pg_catalog."default", balance bigint ) WITH ( OIDS = FALSE ) TABLESPACE pg_default;

ALTER TABLE public."XAccount" OWNER to postgres;

@getquill/maintainers

fwbrasil commented 7 years ago

Thank you for the detailed report! Please check out the "Query Probing" section of the documentation, the context creation must happen in a separate compilation unit.

Let's keep this issue open to improve the error message.