2

For very large datasets, is it possible to return the results of a scalikejdbc query as a Stream? i.e. where the cursor stays open until the Stream has been exhausted so as to save on memory use? If so, how?

Synesso
  • 37,610
  • 35
  • 136
  • 207

2 Answers2

1

You can return your own iterator via session.toStatementExecutor but then you will have to close things manually or wrap the statements and the session in an object than then you can call close when you are done.

piotr
  • 5,657
  • 1
  • 35
  • 60
1

The foreach operation can help you. http://scalikejdbc.org/documentation/operations.html#foreach-operation

Kazuhiro Sera
  • 1,822
  • 12
  • 15
  • It doesn't seem trivial to have full power of streams with back-pressure by using `foreach`. Here is one implementation I've found https://github.com/longcao/reactive-streams-end-to-end-example Could you please add an example with `foreach` and stream implemenation – Grygoriy Gonchar Sep 10 '16 at 18:01