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

Look into Custom Scan methods #84

Closed
gbdubs opened this issue Dec 18, 2023 · 3 comments
Closed

Look into Custom Scan methods #84

gbdubs opened this issue Dec 18, 2023 · 3 comments

Comments

@gbdubs
Copy link
Contributor

gbdubs commented Dec 18, 2023

Quick cleanup across the board:

#83 (comment)

@gbdubs
Copy link
Contributor Author

gbdubs commented Dec 19, 2023

OK I looked into this today. The way to do this would be to implement database/sql.Scanner, which expects one of a few primitive values. Based on what I read, it looks like the typical use case for implementing DB scanner is when the type is mapped cleanly to a single column. The recommendation for how to do this for multi-column objects is instead to flatten obejects to []byte, the only type flexible enough to be available in the Scanner package, then to deserialize. That seems to be much messier than the status quo, so I'm going to close this out for now. Thankfully, we don't actually read in any objects in the same way in multiple places (which was the intended goal of the comment) - though we do read in portfoliogroupmemberships in two places, we select different fields depending on the context.

@gbdubs gbdubs closed this as completed Dec 19, 2023
@bcspragu
Copy link
Collaborator

Sounds good, though if the need arises: We use pgx, and pgx does support database/sql.Scanner, but there's also more advanced, multi-column support directly in pgtype, e.g. https://pkg.go.dev/github.com/jackc/pgx/v5@v5.5.1/pgtype#hdr-Overview_of_Scanning_Implementation

@gbdubs
Copy link
Contributor Author

gbdubs commented Dec 19, 2023

Ahhh that makes much more sense. Thanks Brandon!

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

No branches or pull requests

2 participants