Skip to content

Merge type PSQLFormat into PostgresFormat #212

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

Merged

Conversation

fabianfett
Copy link
Collaborator

@fabianfett fabianfett commented Feb 14, 2022

Motivation

While rewriting lot's of PostgresNIO internals in the last year, I created new types that very closely match existing types. This was a mistake. I should have tried everything to reuse existing types, and change them as needed.

Changes

  • Remove PSQLFormat
  • Rename PostgresFormatCode to PostgresFormat ⚠️ This increases public API... minor version bump required.
  • Add typealias PostgresFormatCode = PostgresFormat with deprecation to not break public API

Result

  • Fewer types, easier API for adopters.

@codecov-commenter
Copy link

codecov-commenter commented Feb 14, 2022

Codecov Report

Merging #212 (8989e41) into main (cc07811) will increase coverage by 4.14%.
The diff coverage is 44.68%.

❗ Current head 8989e41 differs from pull request most recent head 472692f. Consider uploading reports for the commit 472692f to get more accurate results

@@            Coverage Diff             @@
##             main     #212      +/-   ##
==========================================
+ Coverage   40.44%   44.59%   +4.14%     
==========================================
  Files         116      116              
  Lines        7771     7784      +13     
==========================================
+ Hits         3143     3471     +328     
+ Misses       4628     4313     -315     
Flag Coverage Δ
unittests 44.59% <44.68%> (+4.14%) ⬆️

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

Impacted Files Coverage Δ
Sources/PostgresNIO/Data/PostgresDataType.swift 5.66% <ø> (ø)
Sources/PostgresNIO/Data/PostgresRow.swift 0.00% <0.00%> (ø)
...ces/PostgresNIO/Message/PostgresMessage+Bind.swift 0.00% <ø> (ø)
...esNIO/Message/PostgresMessage+RowDescription.swift 0.00% <0.00%> (ø)
...es/PostgresNIO/New/Data/Optional+PSQLCodable.swift 47.05% <0.00%> (ø)
Sources/PostgresNIO/New/PSQLCodable.swift 100.00% <ø> (ø)
Sources/PostgresNIO/Postgres+PSQLCompat.swift 0.00% <0.00%> (ø)
Sources/PostgresNIO/New/Data/Int+PSQLCodable.swift 20.26% <10.00%> (+2.61%) ⬆️
...urces/PostgresNIO/New/Data/Bytes+PSQLCodable.swift 73.52% <40.00%> (ø)
...urces/PostgresNIO/New/Data/Array+PSQLCodable.swift 94.68% <50.00%> (+1.06%) ⬆️
... and 42 more

@fabianfett fabianfett requested a review from 0xTim February 15, 2022 13:19
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.

No objections whatsoever to this, just a minor question and one incredibly persnickety nitpick, neither is in any way blocking 👍

I don't think it was a mistake to add the new types at the time, incidentally - given the somewhat uneven quality of the old implementation, it mades sense to start with a type that could be freely tinkered with as needed rather than try to squeeze a new implementation into the old one's limitations. I do agree the extra type is obsolete at this point, though.

Also I just like the shorter type names 🤣

@@ -14,6 +17,13 @@ public enum PostgresFormatCode: Int16, Codable, CustomStringConvertible {
}
}

// TODO: The Codable conformance does not make any sense. Let's remove this with next major break.
Copy link
Member

Choose a reason for hiding this comment

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

IIRC, enums that get synthesized RawRepresentable by declaring an enumerator type automatically get Codable if the raw type is via RawRepresentable's conditional conformance anyway - was that what you were referring to with "does not make any sense?" (The phrasing is a little confusing to me; I'm wondering if I missed any additional issues.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"does not make sense" relates to the unlikeliness of users wanting to put a PostgresFormat into json/xml/yaml.

/// Currently there a two wire formats supported:
/// - text
/// - binary
public enum PostgresFormat: Int16 {
Copy link
Member

Choose a reason for hiding this comment

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

I've gotten into the habit of tossing CaseIterable conformance on any enum I can unless there's a reason not to, on the theory that it tends to come in handy when testing, debugging, doing anything reflection-like, etc. Any reason not to put it on this one? (Other than it conceptually reducing to Bool unless Postgres's wire protocol someday comes up with additional formats 😆) I know it's overkill and there's no present need for it, I'm not gonna debate the point if you'd rather not add it (though, being me, I will probably grumble to myself just to be contrary 😉)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wouldn't oppose adding it... However everything that is public API, will make binaries larger as it can't be stripped as long as we don't have lto. That's why I refrain from adding auto synthesized conformances normally. If I don't need it they are not allowed to take up bytes.

@fabianfett fabianfett merged commit 55d6b9d into vapor:main Feb 17, 2022
@fabianfett fabianfett deleted the ff-merge-psqlformat-with-postgresformat branch February 17, 2022 18:11
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