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

Extend typing to make JSON expressions work with order #390

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mqp
Copy link
Contributor

@mqp mqp commented Jan 17, 2023

Previously, if you wrote a query like this:

// presumes a table foos that has a JSONB `data` column
const { data, error } = await client.from('foos').select('id').order('data->>count', { ascending: true })

It would fail to typecheck, because the typing for order thought that if the first parameter isn't a column name from the foos table in the schema, then it must be a foreign table reference, so the foreignTable property in the options must be specified.

Now, Typescript can extract the column name from the data->>count expression, and check that against the schema.

I think there are other expressions you can use here (the Postgrest docs mention computed columns) but this covers the JSON accessor case. (We could also probably use similar code in the filter builder to get better typechecking when using JSON accessors in a variety of methods.)

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.

1 participant