Closed deusaquilus closed 6 years ago
Hello,
You need to make context trait member to be abstract val
:
trait SomeSchema {
val ctx: SqlContext[_, _]
import ctx._
def select = quote {
query[Person].filter(p => p.age > 21)
}
}
And the use it in successors as:
class Test(val ctx: SqlMirrorContext[MirrorSqlDialect, SnakeCase]) extends SomeSchema {
import ctx._
def runSelect = run(select)
}
Working example: https://scastie.scala-lang.org/j9k22KuATQqNftgv4xjNwA
Feel free to re-open this issue if this is not something you'd like to achieve
This template isn't a strict requirement to open issues, but please try to provide as much information as possible.
Version:
2.3.2
Module:quill-sql
,quill-jdbc
Database: AllA nice way to be able to be able to compose contexts would be to define them as values of a trait, and then extend that trait later with an actual context and run the query.
For example, let's define a trait:
Now let's define our main method where we extend it with an actual context and try to run a query:
This causes the following error at
run(traitImpl.query)
You can see this issue on Scastie here: https://scastie.scala-lang.org/deusaquilus/GWGSaFJxSLSjuK5nFsw7cA
Alternatively, even if you use a trait with the context as a global import the same problem happens:
You can see this second case on Scastie here: https://scastie.scala-lang.org/deusaquilus/Qr6CAEIaT3ChsLVKjA4O4Q
Similarly, if you decide to try to define a context via a class import, it also does not work although I am not sure whether this last example should actually work or not.
Class importing a context:
Later it gets used like this:
This causes the following:
You can find an example of this latter issue here: https://scastie.scala-lang.org/deusaquilus/tpfNL6puSXyV74vcYPAwJg
Workaround
None that I know of. This kind of cake-pattern usage does not work with Quill.
@getquill/maintainers
Edit: One more example.