ImplicitSyntax
io.getquill.context.qzio.ImplicitSyntax
object ImplicitSyntax
Use to provide run(myQuery)
calls with a context implicitly saving the need to provide things multiple times. For example in JDBC:
case class MyQueryService(ds: DataSource with Closeable) {
import Ctx._
implicit val env = Implicit(Has(ds))
val joes = Ctx.run(query[Person].filter(p => p.name == "Joe")).onDataSource.implicitly
val jills = Ctx.run(query[Person].filter(p => p.name == "Jill")).onDataSource.implicitly
val alexes = Ctx.run(query[Person].filter(p => p.name == "Alex")).onDataSource.implicitly
}
Normally you would have to do a separate provide
for each clause:
val joes = Ctx.run(query[Person].filter(p => p.name == "Joe")).onDataSource.provide(Has(ds))
val jills = Ctx.run(query[Person].filter(p => p.name == "Jill")).onDataSource.provide(Has(ds))
val alexes = Ctx.run(query[Person].filter(p => p.name == "Alex")).onDataSource.provide(Has(ds))
For other contexts where the environment returned from run(myQuery)
just the session itself, usage is even simpler. For instance, in quill-zio-cassandra, you only need to specify implicitly
.
case class MyQueryService(cs: CassandraZioSession) {
import Ctx._
implicit val env = Implicit(Has(cs))
def joes = Ctx.run { query[Person].filter(p => p.name == "Joe") }.implicitly
def jills = Ctx.run { query[Person].filter(p => p.name == "Jill") }.implicitly
def alexes = Ctx.run { query[Person].filter(p => p.name == "Alex") }.implicitly
}
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
ImplicitSyntax.type
Members list
In this article