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 Interpolation #83

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

Improve CQL Interpolation #83

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

Comments

@nMoncho
Copy link
Owner

nMoncho commented Dec 9, 2023

Problem

CQL Interpolation supports interpolating Scala constants (ie. final vals) by injecting values in place. Depending on the injection position, these values need to be quoted:

final val tableName = "table"
final val queryParam = "some_string"

def query(param: String) =
	cql"SELECT * FROM \"${table}\" WHERE some_column = '${queryParam}' AND other_column = $param"

Since table is a reserved word we need to quote it with double quotes, and since queryParam will be injected we need single quotes (it's on query parameter position). On the other hand param will be replaced with a named bind parameter. The prepared query will be:

SELECT  * FROM "table" WHERE some_column = 'some_string' AND other_column = ?

Desired Solution

Users shouldn't need care about quoting injected values, Helenus should be able to decide when and how to quote injected values, so we end up with Scala code like:

def query(param: String) =
	cql"SELECT * FROM ${table} WHERE some_column = ${queryParam} AND other_column = $param"

Which provides the same valid CQL output

@nMoncho nMoncho added the enhancement New feature or request label Dec 9, 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