Skip to content

Remove use of Row#getAnyOption from FinaglePostgresDecoders#1848

Merged
juliano merged 2 commits into
zio:masterfrom
jonathan-ostrander:finagle-postgres-decoders
May 20, 2020
Merged

Remove use of Row#getAnyOption from FinaglePostgresDecoders#1848
juliano merged 2 commits into
zio:masterfrom
jonathan-ostrander:finagle-postgres-decoders

Conversation

@jonathan-ostrander

Copy link
Copy Markdown
Contributor

Fixes #1844

Problem

The decoders that are not direct in FinaglePostgresDecoders rely on Row#getAnyOption. Row#getAnyOption relies on custom receiving functions being defined on the PostgresClient. postgres-finagle could define these by default (which it probably should), but by default it does not. When custom receiving functions are not defined, Row#getAnyOption always returns None.

Solution

This change introduces an orElse method on FinaglePostgresDecoder which allows for composition of ValueDecoders that was previous being accomplished by PartialFunctions. This solution removes the need for ClassTag (although we may want to keep it to keep error messages consistent) as well as the reliance on Row#getAnyOption.

Notes

This removes the definition of decoder[T] which I do not see much value in since it requires custom receive functions to be defined for T in order to work.

Checklist

  • Unit test all changes
  • Update README.md if applicable
  • Add [WIP] to the pull request title if it's work in progress
  • Squash commits that aren't meaningful changes
  • Run sbt scalariformFormat test:scalariformFormat to make sure that the source files are formatted

@getquill/maintainers

jonathan-ostrander and others added 2 commits May 5, 2020 12:47
This addresses a part of the cause of issue [zio#1844](zio#1844) which is that the decoders that are not direct in `FinaglePostgresDecoders` rely on `Row#getAnyOption`. `Row#getAnyOption` relies on custom receiving functions being defined on the `PostgresClient`. postgres-finagle could define these by default (which it probably should), but by default it does not.  When custom receiving functions are not defined, `Row#getAnyOption` always returns `None`.

This change introduces an `orElse` method on `FinaglePostgresDecoder` which allows for composition of `ValueDecoder`s that was previous being accomplished by `PartialFunction`s. This solution removes the need for `ClassTag` (although we may want to keep it to keep error messages consistent) as well as the reliance on `Row#getAnyOption`.  It also removes the definition of `decoder[T]`.

@juliano juliano left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for that! 💯

@juliano
juliano merged commit f0983a1 into zio:master May 20, 2020
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.

Finagle Postgres Int decoder throws when reading a value

2 participants