Created
March 5, 2013 23:09
-
-
Save naaman/5095220 to your computer and use it in GitHub Desktop.
anorm hack to use row cursors
This file contains 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
// hack to get a Stream with a cursor-backed query because anorm doesn't combine the two | |
private def resultSetToStream(sql: SimpleSql[Row])(implicit c: Connection): Stream[SqlRow] = { | |
val stmt = sql.getFilledStatement(c, getGeneratedKeys = false) | |
stmt.setFetchSize(1000) | |
val rs = stmt.executeQuery() | |
val rsMetaData = Sql.metaData(rs) | |
val columns = List.range(1, rsMetaData.columnCount + 1) | |
def data(rs: java.sql.ResultSet) = columns.map(nb => rs.getObject(nb)) | |
Useful.unfold(rs)(rs => if (!rs.next()) { rs.getStatement.close(); None } else Some((new SqlRow(rsMetaData, data(rs)), rs))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried, and I have to say