Treating an SQL ResultSet like a Scala Stream

前端 未结 10 2261
天涯浪人
天涯浪人 2020-12-02 10:11

When I query a database and receive a (forward-only, read-only) ResultSet back, the ResultSet acts like a list of database rows.

I am trying to find some way to trea

10条回答
  •  感情败类
    2020-12-02 10:45

    Another variant on the above, which works with Scala 2.12:

    implicit class ResultSetOps(resultSet: ResultSet) {
     def map[T](f: ResultSet => T): Iterator[T] =
      Iterator.continually(resultSet).takeWhile(_.next()).map(f)
    }
    

提交回复
热议问题