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

RowDecoder #39

Closed
khanlou opened this issue Apr 10, 2022 · 6 comments
Closed

RowDecoder #39

khanlou opened this issue Apr 10, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@khanlou
Copy link

khanlou commented Apr 10, 2022

I've written a RowDecoder, which lets you easily convert from a PostgresClientKit.Row to a Codable struct, like

struct User: Codable {
    let id: Int
    let name: String
}

It's working well in my project, and if you think it'd be good to add to this library, let me know and I would be happy to clean it up and pull request it.

@pitfield
Copy link
Member

Sure, that would be great!

For the PR, please use develop as the base branch (instead of master).

Or, if you prefer, feel free to send me (or point me to) whatever you currently have, and I can integrate it (and credit you in the release notes).

Thanks!

@pitfield pitfield added the enhancement New feature or request label Apr 16, 2022
@khanlou
Copy link
Author

khanlou commented Apr 20, 2022

Here it is:

https://gist.github.com/khanlou/ff3e8788026b35150a9670b87b676ad2

Dates get a little hairy, because you do need a timezone to convert some of the fields to date. I think UTC is a reasonable default since that's what most servers should be running, but you could also parameterize the TZ on RowDecoder.

@pitfield
Copy link
Member

Thanks! I hope to take a look this weekend.

@pitfield
Copy link
Member

pitfield commented May 1, 2022

This looks good; thank you.

I'm going to try adding a couple of things:

  • Making PostgresTimestampWithTimeZone, PostgresTimestamp, PostgresDate, and PostgresTime conform to Decodable. I think this is the cleanest way to get dates/times out. I like your suggestion of parameterizing the time zone on the Decoder, if someone wants to decode to a Foundation Date property.

  • Add a second flavor of Decoder that can be used if retrieveColumnMetadata is false, by assuming the result set columns are in CodingKeys order (or, if CodingKeys is synthesized, in declaration order).

@khanlou
Copy link
Author

khanlou commented May 1, 2022

I like both of those ideas. I’m messing with time zone heavy code today and assuming utc on decode I’m not sure is the right decision.

pitfield added a commit that referenced this issue May 12, 2022
Thanks to @khanlou for the idea and initial code.

Co-authored-by: Soroush Khanlou (@khanlou)
pitfield added a commit that referenced this issue Aug 24, 2022
pitfield added a commit that referenced this issue Aug 24, 2022
Thanks to @khanlou for the idea and initial code.

Co-authored-by: Soroush Khanlou (@khanlou)
pitfield added a commit that referenced this issue Aug 24, 2022
pitfield added a commit that referenced this issue Aug 24, 2022
Thanks to @khanlou for the idea and initial code.

Co-authored-by: Soroush Khanlou (@khanlou)
pitfield added a commit that referenced this issue Aug 24, 2022
pitfield added a commit that referenced this issue Aug 30, 2022
Thanks to @khanlou for the idea and initial code.

Co-authored-by: Soroush Khanlou (@khanlou)
@pitfield
Copy link
Member

Released in v1.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants