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

Merge PSQLDataType with PostgresDataType #213

Merged

Conversation

fabianfett
Copy link
Collaborator

Motivation

While rewriting lot's of PostgresNIO internals 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 PSQLDataType and replace all uses with PostgresDataType

Result

Fewer types, easier API for adopters.

@fabianfett fabianfett force-pushed the ff-merge-psqldatatype-with-postgresdatatype branch from 891d693 to 52397d2 Compare February 14, 2022 08:27
@@ -16,7 +16,7 @@ public enum PostgresFormatCode: Int16, Codable, CustomStringConvertible {

/// The data type's raw object ID.
/// Use `select * from pg_type where oid = <idhere>;` to lookup more information.
public struct PostgresDataType: Codable, Equatable, ExpressibleByIntegerLiteral, CustomStringConvertible, RawRepresentable {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note: I have moved the Codable and ExpressibleByIntegerLiteral further down and added a remove TODO for the next major version break.

@codecov-commenter
Copy link

codecov-commenter commented Feb 14, 2022

Codecov Report

Merging #213 (52eb091) into main (55d6b9d) will increase coverage by 4.39%.
The diff coverage is 81.25%.

@@            Coverage Diff             @@
##             main     #213      +/-   ##
==========================================
+ Coverage   40.44%   44.83%   +4.39%     
==========================================
  Files         116      116              
  Lines        7771     7719      -52     
==========================================
+ Hits         3143     3461     +318     
+ Misses       4628     4258     -370     
Flag Coverage Δ
unittests 44.83% <81.25%> (+4.39%) ⬆️

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

Impacted Files Coverage Δ
Sources/PostgresNIO/New/Messages/Parse.swift 100.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% <30.00%> (+2.61%) ⬆️
...es/PostgresNIO/New/Data/Optional+PSQLCodable.swift 47.05% <50.00%> (ø)
...ces/PostgresNIO/New/Data/Decimal+PSQLCodable.swift 74.19% <57.14%> (+6.45%) ⬆️
Sources/PostgresNIO/Data/PostgresDataType.swift 52.83% <100.00%> (+47.16%) ⬆️
...urces/PostgresNIO/New/Data/Array+PSQLCodable.swift 94.68% <100.00%> (+1.06%) ⬆️
...ources/PostgresNIO/New/Data/Bool+PSQLCodable.swift 95.34% <100.00%> (+4.65%) ⬆️
...urces/PostgresNIO/New/Data/Bytes+PSQLCodable.swift 73.52% <100.00%> (ø)
... and 38 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.

Pretty much copy and paste what I wrote for #212, I love cleanup work ❤️

// TODO: The Codable conformance does not make any sense. Let's remove this with next major break.
extension PostgresDataType: Codable {}

// TODO: The ExpressibleByIntegerLiteral conformance does not make any sense and is not used anywhere. Remove 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.

My guess would be that Tanner probably used this during dev to be able to just drop raw data type codes in for quick testing 'cause it felt more convenient than having to add the .init() boilerplate (I can understand the feeling! 😅). Of course, then he either just forgot about it later or looked at it and went "well why not just leave it in" - he was happy to let me take the role of overzealous code neat freak 😆

(I'm 100% in favor of ditching it regardless of all that, all it does is make it easier to misuse the API.)

@@ -227,3 +222,13 @@ public struct PostgresDataType: Codable, Equatable, ExpressibleByIntegerLiteral,
return self.knownSQLName ?? "UNKNOWN \(self.rawValue)"
}
}

// 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.

Was there a point in early Swift 5 before RawRepresentable automatically conferred Codable? That would make sense of why the redundant conformance was left in. (I mean heck, I tend to write out Equatable, Hashable by habit and then grumble at the compiler warning complaining Equatable is redundant...)

Though, given that the conformance is automatically bestowed regardless, does the removal of the explicit declaration actually have to wait for a major version break?

(Hm, do structs get it automatically? Or just enums? Either way, the enum in the other PR could lose it without a major version break at least.)

@gwynne
Copy link
Member

gwynne commented Feb 17, 2022

Sigh, merge conflicts. You'd think Git would be smart enough to be able to tell #212 and this are directly related 😒

@fabianfett fabianfett force-pushed the ff-merge-psqldatatype-with-postgresdatatype branch from 258a149 to 52eb091 Compare February 17, 2022 18:19
@fabianfett fabianfett merged commit eaef208 into vapor:main Feb 17, 2022
@fabianfett fabianfett deleted the ff-merge-psqldatatype-with-postgresdatatype branch February 17, 2022 19:44
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