I am using postgresql 9.6, slick 3.2 and slick-pg is connected.
I implement a graph backend in Scala, and I need to implement queries to solve GraphQL cursors of various forms. The input forms are enumerated. Some of the inputs that affect the request may be:
- user selectable order.
- various filtering criteria (full-text search, date ranges, etc.).
- choice between reverse or direct bypass.
My current simple cursors have reverse and direct hardcoded as compiled queries. Both have the same shape, and I use standard slip abbreviations to take into account the commonality for reuse (value classes with ops, inheritance hierarchy for entity tables and code generation). But there are many more templates, and it wonβt scale to more dynamic forms unless I have listed all of them.
here is an excerpt from the class that uses this template:
private [shard] class SchemaAllTypeCursor(shard: SlickShard) extends CursorSpec[TypeModel] {
import shard.PostgresProfile.api._
private val forwardQC = Compiled { (tenantIdUrls: Rep[List[String]], low: Rep[Long], take: ConstColumn[Long]) =>
Queries.listTypesByTenantIds(tenantIdUrls).forwardCursorById(low, take)
}
private val backwardQC = Compiled { (tenantIdUrls: Rep[List[String]], high: Rep[Long], take: ConstColumn[Long]) =>
Queries.listTypesByTenantIds(tenantIdUrls).backwardCursorById(high, take)
}
def executor(tenantIdUrls: List[String])(c: CursorRequest)(implicit req: Req[_]): Observable[TypeModel] = {
implicit val ec = req.ctx.ec
Observable fromFuture {
shard.db.run {
if (c.forward) forwardQC(tenantIdUrls, c.base, c.take).result
else backwardQC(tenantIdUrls, c.base, c.take).result
} flatMap materializeAllTypes(req.ctx, tenantIdUrls)
} flatMap Observable.fromIterable
}
}
General question: how do I get compiled queries for this use case without a mountain template? Some ideas I would like to get are:
- ?
backwardCursorById forwardCursorById . , -.... - ? ( , , ).
- , ? -- . , .
postgres, slick-pg.