zio-quill
zio-quill copied to clipboard
quill-cassandra: custom per-query consistency level
Is there any way to set consistency in each query right now?
@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
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
}