Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CQL Options #86

Open
nMoncho opened this issue Dec 13, 2023 · 0 comments
Open

Improve CQL Options #86

nMoncho opened this issue Dec 13, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@nMoncho
Copy link
Owner

nMoncho commented Dec 13, 2023

Description

We can setup CQL Options at the PreparedStatement definition as a way to avoid defining them on BoundStatement level, like:

val queryAll = "SELECT * FROM hotels".toCQL.prepareUnit
        .withConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM)
        .withTimeout(Duration.ofHours(1))
        .withPageSize(10)
        .withTracing(enabled = true)
        .withExecutionProfile(session.executionProfile("default").get)

But the way these options are applied to the actual BoundStatement can be a bit inefficient:

      val bs1 = bs.setTracing(tracing).setPageSize(pageSize)
      val bs2 = profile.map(bs1.setExecutionProfile).getOrElse(bs1)
      val bs3 = routingKeyspace.map(bs2.setRoutingKeyspace).getOrElse(bs2)
      val bs4 = routingKey.map(bs3.setRoutingKey).getOrElse(bs3)
      val bs5 = timeout.map(bs4.setTimeout).getOrElse(bs4)
      val bs6 = pagingState.map(bs5.setPagingState).getOrElse(bs5)

      consistencyLevel.map(bs6.setConsistencyLevel).getOrElse(bs6)

We would like this to be simplified with only the desired options.

Solution Description

The current solution may be a bit inefficient but by keeping Options into a case class we can avoid calling the same method twice (e.g. pstmt.withTracing(true).withTracing(false) would only call setTracing once)

@nMoncho nMoncho added the enhancement New feature or request label Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant