Last active
July 21, 2026 09:11
-
-
Save jeroenr/fa06c8aac8cddd5afa468fd5555249f1 to your computer and use it in GitHub Desktop.
Cursor Based Streaming with Kotlin Sequence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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