Skip to content

Instantly share code, notes, and snippets.

@jeroenr
Last active July 21, 2026 09:11
Show Gist options
  • Select an option

  • Save jeroenr/fa06c8aac8cddd5afa468fd5555249f1 to your computer and use it in GitHub Desktop.

Select an option

Save jeroenr/fa06c8aac8cddd5afa468fd5555249f1 to your computer and use it in GitHub Desktop.
Cursor Based Streaming with Kotlin Sequence
dataSource.connection.use { connection ->
connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY).use { statement ->
statement.fetchSize = fetchSize
statement.queryTimeout = queryTimeoutSeconds
statement.executeQuery().use { resultSet ->
val rows = generateSequence {
if (resultSet.next()) mapRow(resultSet) else null
}
consumer(rows)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment