I am migrating my application from Cassandra to Postgres. While I used Datastax driver to dynamically generate cql queries, I am having trouble doing the same with slick.
When I say dynamic, I mean I am getting my column names and their values as a map {(key, v) => key.name -> v} from a service and I wish to plug these in the query generated in my Postgres DAO API using slick.
Here is a sample code for Cassandra:
private lazy val getStatement: PreparedStatement = {
val select: Select = QueryBuilder.select(valueColumns.map(_.name): _*).from(KeyspaceName, TableName)
val where: Where = select.where()
keyColumns.foreach(col => where.and(QueryBuilder.eq(col.name, bindMarker)))
table.session.getSession.prepare(select)
}
val bs: BoundStatement = getStatement.bind
val updatedKeys = keys.map { case (column, value) => (column, Option(value)) }
writeKeys(updatedKeys, bs) //this method modifies the bound statement to plug in values
val resultSet: ResultSet = table.session.getSession.execute(bs)
What is the alternative to this - for better reuse of a certain query across different tables. Also to further extend it across diff column names ?
How can I achieve this using slick?