What is the right way to work with slick's 3.0.0 streaming results and Postgresql?
The "right way" to do streaming with Slick and Postgres includes three things:
Must use db.stream()
Must disable
autoCommit
in JDBC-driver. One way is to make the query run in a transaction by suffixing.transactionally
.Must set
fetchSize
to be something else than 0 or else postgres will push the whole resultSet to the client in one go.
Ex:
DB.stream( find(0L, 0L) .transactionally .withStatementParameters(fetchSize = 1000)).foreach(println)
Useful links:
The correct way to stream in Slick is as provided in documentation is
val q = for (c <- coffees) yield c.imageval a = q.resultval p1: DatabasePublisher[Blob] = db.stream(a.withStatementParameters(rsType = ResultSetType.ForwardOnly, rsConcurrency = ResultSetConcurrency.ReadOnly, fetchSize = 1000 /*your fetching size*/).transactionally)