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

We should consolidate DB result parsing #228

Open
slifty opened this issue Feb 7, 2023 · 1 comment
Open

We should consolidate DB result parsing #228

slifty opened this issue Feb 7, 2023 · 1 comment
Assignees

Comments

@slifty
Copy link
Member

slifty commented Feb 7, 2023

Right now we in every endpoint we guard against the database response to ensure the database provided a valid type.

As we've implemented more endpoints (and more complex endpoints) we're increasingly duplicating those checks and, more meaningfully, duplicating the need for complicated mocks in our tests.

This came to a head in #210

It would be good to explore creating a centralized helper function that will run a database query and properly parse / handle / throw in the event of an issue. This could hopefully cut down on duplicated test coverage.

@slifty
Copy link
Member Author

slifty commented Apr 6, 2023

On this note -- we can actually use TS generics to signal what type of object is going to be returned by a given db.sql call -- however this is just a type signal and if the query is malformed it could result in a lack of type safety.

I'm inclined to prefer to have type guards since they verify the returned value's type at runtime, but wanted to raise the option in case others felt that was overkill. For instance maybe a better approach would be to protect against malformed queries is to write tests against he query specifically so the tests would fail if they are incorrect. This would potentially allow for edge cases but would result in more succinct code.

For what its worth our current type guard actually only exists to validate the response before sending it -- the fact that it happens to be a type guard is really secondary. So I guess this is more a question of: do we want our code to validate that our return value is, in fact, the documented schema before returning it.

slifty added a commit that referenced this issue Mar 28, 2024
This is part of our effort to update the query logic for our entities
via database operation utility functions.  This will also pave the way
for supporting the new `json` approach to our queries.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue Mar 28, 2024
This is part of our effort to update the query logic for our entities
via database operation utility functions.  This will also pave the way
for supporting the new `json` approach to our queries.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue Mar 28, 2024
This is part of our effort to update the query logic for our entities
via database operation utility functions.  This will also pave the way
for supporting the new `json` approach to our queries.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue Mar 28, 2024
This is part of our effort to update the query logic for our entities
via database operation utility functions.  This will also pave the way
for supporting the new `json` approach to our queries.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue Mar 29, 2024
This is part of our effort to update the query logic for our entities
via database operation utility functions.  This will also pave the way
for supporting the new `json` approach to our queries.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue Mar 29, 2024
This is part of our ongoing work of creating type safe utility methods
for interacting with the database.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue Mar 29, 2024
This is part of our ongoing work of creating type safe utility methods
for interacting with the database.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue Mar 29, 2024
This is part of our ongoing work of creating type safe utility methods
for interacting with the database.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue Mar 29, 2024
This continues along our consolidation work for DB interactions.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue Mar 29, 2024
This continues along our consolidation work for DB interactions.

Issue #228 We should consolidate DB result parsing
@slifty slifty self-assigned this Apr 2, 2024
slifty added a commit that referenced this issue Apr 29, 2024
This modernizes our opportunity db access and also updates the
collection endpoint to return a bundle, consistent with other collection
endpoints.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue Apr 29, 2024
This modernizes our opportunity db access and also updates the
collection endpoint to return a bundle, consistent with other collection
endpoints.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue Apr 29, 2024
This modernizes our opportunity db access and also updates the
collection endpoint to return a bundle, consistent with other collection
endpoints.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue Apr 29, 2024
This modernizes our opportunity db access and also updates the
collection endpoint to return a bundle, consistent with other collection
endpoints.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue May 2, 2024
Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue May 2, 2024
Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue May 2, 2024
Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue May 2, 2024
Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue May 2, 2024
Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue May 10, 2024
Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue May 10, 2024
Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue May 15, 2024
Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue May 15, 2024
Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue May 15, 2024
Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue May 22, 2024
This was missed when we did an earlier transition to using centralized
DB utilities for organization interactions.

Issue #228 We should consolidate DB result parsing
slifty added a commit that referenced this issue May 23, 2024
This was missed when we did an earlier transition to using centralized
DB utilities for organization interactions.

Issue #228 We should consolidate DB result parsing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

1 participant