Executes the cursored statement with the given params
and lazily maps f
over the rows as they are streamed from the database.
Executes the cursored statement with the given params
and lazily maps f
over the rows as they are streamed from the database.
For Scala users, you can use the implicit conversions to Parameter
by importing Parameter._
. For example:
import com.twitter.finagle.mysql.{Client, CursorResult, CursoredStatement} import com.twitter.finagle.mysql.Parameter._ import com.twitter.concurrent.AsyncStream import com.twitter.util.Future val client: Client = ??? val cursoredStatement: CursoredStatement = client.cursor("SELECT int_column FROM a_table WHERE string_column = ?") val rowsToFetch = 100 val futureCursorResult: Future[CursorResult[Int]] = // note the implicit conversions of the String to Parameter cursoredStatement(rowsToFetch, "cool example") { row => row.intOrZero } futureCursorResult.foreach { cursorResult => val stream: AsyncStream[Int] = cursorResult.stream stream.take(5).foreach { i => println(s"Read int_column = '$i'"); }.ensure { cursorResult.close() } }
Java users, see asJava and use CursoredStatement.AsJava.execute.
should be picked to balance the minimum number of round trips to the database, and the maximum amount of memory used by an individual fetch.
Provides a Java-friendly API for this CursoredStatement.
A
CursoredStatement
represents a parameterized SQL statement applied concurrently with varying parameters and yields a lazy stream of rows.These are SQL statements with
?
's used for the parameters which are "filled in" per usage byapply
.PreparedStatement for eager processing of Rows.
Client.cursor(String