akka / alpakka

Alpakka is a Reactive Enterprise Integration library for Java and Scala, based on Reactive Streams and Akka.
https://doc.akka.io/docs/alpakka/current/
Other
1.26k stars 646 forks source link

Not all Slick sources stream by default #1128

Open arnold-jr opened 6 years ago

arnold-jr commented 6 years ago

This is an issue of documentation clarity: as per Slick's documentation, not all databases (most notably PostgreSQL) require .withStatementParameters in order to get results returned asynchronously. So a truly streaming query would look like

val typedSelectAllUsers = TableQuery[Users].result
          .withStatementParameters(
            rsType = ResultSetType.ForwardOnly,
            rsConcurrency = ResultSetConcurrency.ReadOnly,
            fetchSize = conf.getInt("batchSize")
          )

This might be a useful addition to the docs, since DBs that will fit entirely into memory are more the exception than the rule :)

Thanks!

P.S. Incidentally, for PostgreSQL, the fetchSize is not respected!

2m commented 6 years ago

Ahh, good insight! Would you be up for creating a PR for documentation amendment?

WellingR commented 6 years ago

Before I have done some tests with this. And I indeed found that the above is almost the full solution. The last thing that is needed (which is also mentioned in https://github.com/slick/slick/issues/1305 ) is to wrap the query in a .transactionally block

So the truly streaming query would look like

val typedSelectAllUsers = TableQuery[Users].result
          .withStatementParameters(
            rsType = ResultSetType.ForwardOnly,
            rsConcurrency = ResultSetConcurrency.ReadOnly,
            fetchSize = conf.getInt("batchSize")
          )
          .transactionally
Sh1ftry commented 4 years ago

Shouldn't this be explicitly pointed in the Slick Alpakka documentation? By looking at example that is present in the documentation I can assume that using Slick.source(TableQuery[Users].result) is enough to enable streaming, which is not true, because whole result would be first loaded into memory for some databases.