What is the right way to work with slick's 3.0.0 streaming results and Postgresql?

前端 未结 2 808
孤街浪徒
孤街浪徒 2021-02-04 08:15

I am trying to figure out how to work with slick streaming. I use slick 3.0.0 with postgres driver

The situation is following: server have to give client sequences of da

2条回答
  •  鱼传尺愫
    2021-02-04 08:23

    The "right way" to do streaming with Slick and Postgres includes three things:

    1. Must use db.stream()

    2. Must disable autoCommit in JDBC-driver. One way is to make the query run in a transaction by suffixing .transactionally.

    3. 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:

    https://github.com/slick/slick/issues/1038

    https://github.com/slick/slick/issues/809

提交回复
热议问题