-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Update Type Implementation (postgrest-js side) #152
Conversation
users[0].username | ||
users[0].somethingElse |
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 are for some reason nullable, but I can't find what in the code actually does it... They weren't nullable before and they aren't in other tests..
if (Array.isArray(columns)) { | ||
columns = columns.join(',') | ||
} |
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.
This handles the array select input
@@ -21,7 +21,7 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> { | |||
* @param count Count algorithm to use to count rows in a table. | |||
*/ | |||
select( | |||
columns = '*', | |||
columns: '*' | string | keyof T | Array<keyof 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.
This will show '*'
, and the column names as suggestions, while still allowing a comma-separated string
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.
If this is going to be a part of a breaking change, I would recommend removing string
(and therefore comma separated strings) as an option - IIRC it will then error if you give it an unknown column if a table type is passed in, and will result in string
if no custom table type is passed.
columns: '*' | keyof T | Array<keyof T> = '*',
Went digging looking for how to type |
We're working on this as part of the Supabase v2 release (supabase/supabase-js#170), but that will be after Launch Week (next week). We'll do some project planning in August and should have a better idea of dates then @jonlambert |
Brilliant, thanks @kiwicopple. I'll keep an eye out for that release. |
Guess I can close these now. |
What kind of change does this PR introduce?
A breaking type update, which allows easier and stricter type checking. This is a combined update for this package and
supabase-js
.supabase/supabase-js#125
What is the current behavior?
.from<User>('users')
every time you use it..select()
does not have any intellisense help.What is the new behavior?
You get intellisense suggestions in
.select()
.You now pass the schema into the
PostgrestClient
, and let the types handle the rest from there.The schema type is based on what
openapi-typescript
generates, as recommended in the supabase guide (which also has to be updated as the tool has renamed).Additional context
Not passing in a type still works as before, with any names working and returning
any
.I tried very hard to not make this a breaking change, by still allowing
.from<Object>()
, but it's sadly impossible without some crazy workarounds. 😢This package will have to be released before
supabase-js
so #123 can be updated to use the new version.