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

Add new protocol PostgresNonThrowingEncodable #322

Merged
merged 2 commits into from
Jan 21, 2023

Conversation

fabianfett
Copy link
Collaborator

Motivation

Currently creating a PostgresQuery through String interpolation always throws. The reason to support throwing in PostgresEncodable is, that the Encodable protocol enforces throwing (and we do want to support JSON). But for most of the primary types throwing is totally useless.

Changes

  • We introduce the protocol PostgresNonThrowingEncodable, which inherits from PostgresEncodable but enforces that the encode method does not throw
  • We add a separate entry points for PostgresNonThrowingEncodable in PostgresQuery and PostgresBinding to reduce the number of places where we throw

Result

  • way less throwing in places where we don't actually throw

@fabianfett fabianfett force-pushed the ff-PostgresNonThrowingEncodable branch from cb7501f to a9b1f1f Compare January 2, 2023 10:02
@codecov-commenter
Copy link

codecov-commenter commented Jan 2, 2023

Codecov Report

Merging #322 (a9b1f1f) into main (b5cca72) will decrease coverage by 0.08%.
The diff coverage is 94.91%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #322      +/-   ##
==========================================
- Coverage   41.62%   41.54%   -0.09%     
==========================================
  Files         115      115              
  Lines        9377     9436      +59     
==========================================
+ Hits         3903     3920      +17     
- Misses       5474     5516      +42     
Flag Coverage Δ
unittests 41.54% <94.91%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...es/PostgresNIO/New/Data/Bool+PostgresCodable.swift 95.34% <ø> (ø)
...s/PostgresNIO/New/Data/Bytes+PostgresCodable.swift 64.70% <ø> (ø)
...es/PostgresNIO/New/Data/Date+PostgresCodable.swift 89.28% <ø> (ø)
...s/PostgresNIO/New/Data/Float+PostgresCodable.swift 76.66% <ø> (ø)
...ces/PostgresNIO/New/Data/Int+PostgresCodable.swift 36.60% <ø> (ø)
.../PostgresNIO/New/Data/String+PostgresCodable.swift 100.00% <ø> (ø)
...es/PostgresNIO/New/Data/UUID+PostgresCodable.swift 96.96% <ø> (ø)
...s/PostgresNIO/New/Data/Array+PostgresCodable.swift 70.94% <89.28%> (-22.32%) ⬇️
Sources/PostgresNIO/New/PostgresCodable.swift 93.87% <100.00%> (+2.21%) ⬆️
Sources/PostgresNIO/New/PostgresQuery.swift 75.00% <100.00%> (-12.18%) ⬇️
... and 2 more

@fabianfett fabianfett marked this pull request as ready for review January 2, 2023 10:27
Copy link
Member

@gwynne gwynne left a comment

Choose a reason for hiding this comment

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

*mutter mutter grumble*

@fabianfett fabianfett merged commit ffb5121 into vapor:main Jan 21, 2023
@fabianfett fabianfett deleted the ff-PostgresNonThrowingEncodable branch January 21, 2023 14:46
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.

3 participants