-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Remove PSQLJSONDecoder from PSQLConnection #214
Remove PSQLJSONDecoder from PSQLConnection #214
Conversation
Codecov Report
@@ Coverage Diff @@
## main #214 +/- ##
==========================================
+ Coverage 40.46% 44.57% +4.10%
==========================================
Files 116 116
Lines 7777 7778 +1
==========================================
+ Hits 3147 3467 +320
+ Misses 4630 4311 -319
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
||
extension PSQLRow { | ||
func decode<T: PSQLDecodable>(column: String, as type: T.Type, file: String = #file, line: Int = #line) throws -> T { | ||
try self.decode(column: column, as: type, jsonDecoder: JSONDecoder(), file: file, line: line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe worth to create a JSONDecoder
once (e.g. as a static let) and reuse it here to safe a couple of allocations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two methods have only been added right now, to not rewrite large parts of the tests. They will not become public API, as PSQLRow will be merged with PostgresRow in the future. Then we should def. consider keeping a longer ref to JSONDecoder and JSONEncoder around.
try self.decode(column: column, as: type, jsonDecoder: JSONDecoder(), file: file, line: line) | ||
} | ||
|
||
func decode<T: PSQLDecodable>(column index: Int, as type: T.Type, file: String = #file, line: Int = #line) throws -> T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func decode<T: PSQLDecodable>(column index: Int, as type: T.Type, file: String = #file, line: Int = #line) throws -> T { | |
func decodeColumn<T: PSQLDecodable>(at columnIndex: Int, as type: T.Type = T.self, file: String = #file, line: Int = #line) throws -> T { |
Nit: makes the naming a bit more swiftier (is this even a word? :D)
Similar, decode
where column
is a String
could be decodeColumn(named:as:)
or just decodeColumn(_:as:)
Will this be public API?
Motivation
Currently we attach a PSQLJSONDecoder and PSQLJSONEncoder to a PostgresConnection. This is not ideal. Instead users should be able to supply an encoder and decoder on a per query basis.
Changes
Result