-
-
Notifications
You must be signed in to change notification settings - Fork 137
Is there streaming support? #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you for reporting an issue. See the wiki for documentation and gitter for questions. |
Hi, streaming is not supported at the moment. Contribution is welcome of course. |
I implemented this (postgres specific) for scrolling through large result sets. Might be interesting to add some variation of this. suspend fun queryFlow(query: String, params: List<Any>, fetchSize: Int = 100) : Flow<T> {
// use channelFlow for thread safety
return channelFlow {
val producer = this
connection.inTransaction {c ->
val cursorId = "cursor_${Random.nextULong()}"
try {
c.sendPreparedStatement(
"""
DECLARE $cursorId CURSOR FOR
$query
""".trimIndent(), params
)
var resp: QueryResult? = null
while (resp == null || resp.rows.isNotEmpty()) {
resp = c.sendQuery("FETCH $fetchSize FROM $cursorId;")
resp.rows.forEach { row ->
val doc = json.decodeFromString(serializationStrategy,row.getString("json")?: error("empty json"))
producer.send(doc)
}
}
} finally {
c.sendQuery("CLOSE $cursorId;")
}
}
}
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I apologize for asking in an issue but I wasn't sure how to contact you @oshai.
Is there streaming support? Looking at
ResultSet
I see that it's expected to load all query results into a list. My use-case is to pull data in bulk so it could be "select * from table" on a table with billions of rows. I'm happy to contribute but perhaps it's already implemented.The text was updated successfully, but these errors were encountered: