Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make result set an iterable #1823

Merged
merged 3 commits into from
May 25, 2021
Merged

Make result set an iterable #1823

merged 3 commits into from
May 25, 2021

Conversation

pm47
Copy link
Member

@pm47 pm47 commented May 25, 2021

This allows us to use the full power of scala collections, to iterate
over results, convert to options, etc. while staying purely functional
and immutable.

There is a catch though: the iterator is lazy, it must be materialized
before the result set is closed, by converting the end result in a
collection or an option. In other words, database methods must never
return an Iterable or Iterator.

@pm47 pm47 requested a review from t-bast May 25, 2021 14:05
This allows us to use the full power of scala collections, to iterate
over results, convert to options, etc. while staying purely functional
and immutable.

There is a catch though: the iterator is lazy, it must be materialized
before the result set is closed, by converting the end result in a
collection or an option. In other words, database methods must never
return an `Iterable` or `Iterator`.
@codecov-commenter
Copy link

codecov-commenter commented May 25, 2021

Codecov Report

Merging #1823 (6ed7c27) into master (98cae45) will decrease coverage by 0.04%.
The diff coverage is 93.54%.

@@            Coverage Diff             @@
##           master    #1823      +/-   ##
==========================================
- Coverage   89.39%   89.35%   -0.05%     
==========================================
  Files         145      145              
  Lines       11034    10973      -61     
  Branches      456      457       +1     
==========================================
- Hits         9864     9805      -59     
+ Misses       1170     1168       -2     
Impacted Files Coverage Δ
...main/scala/fr/acinq/eclair/db/DbEventHandler.scala 93.54% <ø> (+3.22%) ⬆️
...n/scala/fr/acinq/eclair/db/FileBackupHandler.scala 71.42% <ø> (ø)
.../src/main/scala/fr/acinq/eclair/db/NetworkDb.scala 100.00% <ø> (ø)
...src/main/scala/fr/acinq/eclair/db/PaymentsDb.scala 92.85% <ø> (ø)
.../scala/fr/acinq/eclair/db/sqlite/SqliteUtils.scala 100.00% <ø> (ø)
...ain/scala/fr/acinq/eclair/db/pg/PgPaymentsDb.scala 84.81% <37.93%> (-0.51%) ⬇️
...main/scala/fr/acinq/eclair/db/jdbc/JdbcUtils.scala 96.07% <100.00%> (+0.16%) ⬆️
...c/main/scala/fr/acinq/eclair/db/pg/PgAuditDb.scala 98.23% <100.00%> (-0.04%) ⬇️
...ain/scala/fr/acinq/eclair/db/pg/PgChannelsDb.scala 96.29% <100.00%> (-0.05%) ⬇️
...main/scala/fr/acinq/eclair/db/pg/PgNetworkDb.scala 97.84% <100.00%> (-0.03%) ⬇️
... and 15 more

Copy link
Member

@t-bast t-bast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels much more natural than the previous awkward manual handling!

@pm47 pm47 merged commit 4dc2910 into master May 25, 2021
@pm47 pm47 deleted the iterate-db-results branch May 25, 2021 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants