Lagom: Provide support for phantom-dsl

Created on 5 Dec 2017  路  8Comments  路  Source: lagom/lagom

Instead of writing CQL queries in lagom projects it would be nice if we could use phantom-dsl (see https://github.com/outworkers/phantom) and use the lagom infrastructure for the Cassandra session management.

The benefits: The dsl provides a type safe way on querying and writing into the Cassandra database, for example:

case class DomainObject(id: UUID, description: String)

abstract class DomainObjects extends Table[DomainObjects, DomainObject] {
  object id extends UUIDColumn with PartitionKey
  object description extends StringColumn

  def getById(id: UUID): Future[Option[DomainObject]] = {
    select.where(_.id eqs id).one()
  }
}
help wanted persistence-api

Most helpful comment

quill-cassandra-lagom is released! Add libraryDependencies += "io.getquill" %% "quill-cassandra-lagom" % "3.1.0" to your build.sbt, then create a context in your application definition:

  lazy val quillContext: CassandraLagomAsyncContext[SnakeCase]        = wire[CassandraLagomAsyncContext[SnakeCase]]
  lazy val quillStreamContext: CassandraLagomStreamContext[SnakeCase] = wire[CassandraLagomStreamContext[SnakeCase]]

It will reuse Lagom's cassandra session automatically. Then you can use it in quill way in your code:

    import ctx._
    val q = quote(
      query[AnalysisEvent]
        .filter(evt =>
          evt.tenantId == lift(tenantId) &&
            evt.userSetId == lift(userSetId)))
    ctx.run(q)

If you are using CassandraLagomAsyncContext, result will be Future[List[AnalysisEvent]]; if CassandraLagomStreamContext, result will be Source[AnalysisEvent, NotUsed].

All 8 comments

There are several things to consider:

  1. should Phantom reuse Lagom's provided CassandraSession?
  2. should Lagom promote the creation of a generic read side processor which happens to use Phantom (users wold have to handle offset within the Phantom provided Cassandra transaction).
  3. How should this integrate with testkit?
  4. Would it be possible to create a Phantom Connector that's ServiceLocator aware so that contact points don't need to be statically configured?

I think defining a specific third party wouldn't be a good idea. There are many other DSLs to use Cassandra (e.g. quill). I think it would be great to show how can one use different libs to accomplish that in Docs using multiple famous libs.

It might be best to implement this as a separate module, outside the lagom/lagom project.

Seems that I've found a way to use quill in lagom. What kind of project should I create?

This PR make quill to support lagom. Can you help me to review it? @TimMoore @ignasi35

@WayneWang12 In my view, you need to create a separate project for integrating Quill and Lagom. I'm not sure, that Quill team accept your pull request.

@ihostage I'm communicating with them. If they don't accept, I'll create my own project.

Luckily one of quill's maintainers @jilen is Chinese. I can talk to him directly in native language.

quill-cassandra-lagom is released! Add libraryDependencies += "io.getquill" %% "quill-cassandra-lagom" % "3.1.0" to your build.sbt, then create a context in your application definition:

  lazy val quillContext: CassandraLagomAsyncContext[SnakeCase]        = wire[CassandraLagomAsyncContext[SnakeCase]]
  lazy val quillStreamContext: CassandraLagomStreamContext[SnakeCase] = wire[CassandraLagomStreamContext[SnakeCase]]

It will reuse Lagom's cassandra session automatically. Then you can use it in quill way in your code:

    import ctx._
    val q = quote(
      query[AnalysisEvent]
        .filter(evt =>
          evt.tenantId == lift(tenantId) &&
            evt.userSetId == lift(userSetId)))
    ctx.run(q)

If you are using CassandraLagomAsyncContext, result will be Future[List[AnalysisEvent]]; if CassandraLagomStreamContext, result will be Source[AnalysisEvent, NotUsed].

Was this page helpful?
0 / 5 - 0 ratings