zio-quill icon indicating copy to clipboard operation
zio-quill copied to clipboard

quill-cassandra: custom per-query consistency level

Open fwbrasil opened this issue 9 years ago • 3 comments

fwbrasil avatar Jan 27 '16 14:01 fwbrasil

Is there any way to set consistency in each query right now?

vejeta avatar Nov 10 '16 11:11 vejeta

@vejeta the only alternative right now is use multiple context instances, one for each consistency level you need. The consistency level can be set via configuration

fwbrasil avatar Nov 10 '16 16:11 fwbrasil

An example of how to do this with multiple context instances:

package io.getquill

import com.datastax.oss.driver.api.core.ConsistencyLevel
import io.getquill.CassandraZioContext.CIO
import zio.{Has, ZIO}

class CassandraSolrContext[N <: NamingStrategy](n: N, consistencyLevel: ConsistencyLevel)
    extends CassandraZioContext(n) {
  override def prepareRowAndLog(cql: String, prepare: Prepare = identityPrepare): CIO[PrepareRow] =
    for {
      env     <- ZIO.environment[Has[CassandraZioSession]]
      csession = env.get[CassandraZioSession]
      boundStatement <-
        ZIO
          .fromFuture(implicit ec => csession.prepareAsync(cql))
          .mapEffect { r =>
            val row = r.setConsistencyLevel(consistencyLevel)
            prepare(row, csession)
          }
          .map(p => p._2)
    } yield boundStatement
}

calvinlfer avatar Feb 02 '22 14:02 calvinlfer