Raw Statements

In case the library cannot fulfill a specific need you have (it does not have 100% parity with the Java driver’s features) or you otherwise need to build up your own queries as Strings, you can write a raw statement equivalent to what you would pass to a session.execute and still get convenient caching of the prepared statement. Note, however, that you must provide the exact type that the Java driver expects, meaning you need to manually box any Ints, Longs, etc and convert any Maps, Lists, etc to their Java counterparts.

There are two variants, depending on the kind of response you expect:

scala> val rawStatement = sSession.rawStatement("INSERT INTO mykeyspace.mytable (s, i, l) VALUES (?, ?, ?)", "a str", Int.box(1234), Long.box(5678L))
rawStatement: com.weather.scalacass.scsession.SCRawStatement = SCRawStatement(INSERT INTO mykeyspace.mytable (s, i, l) VALUES (a str, 1234, 5678))

scala> rawStatement.execute()
res2: com.weather.scalacass.Result[com.datastax.driver.core.ResultSet] = Right(ResultSet[ exhausted: true, Columns[]])
scala> val rawSelect = sSession.rawSelect("SELECT COUNT(*) FROM mykeyspace.mytable WHERE s = ?", "a str")
rawSelect: com.weather.scalacass.scsession.SCRawSelectStatement[Iterator] = SCRawSelectStatement(SELECT COUNT(*) FROM mykeyspace.mytable WHERE s = a str)

scala> rawSelect.execute()
res3: com.weather.scalacass.Result[Iterator[com.datastax.driver.core.Row]] = Right(non-empty iterator)