-
-
Notifications
You must be signed in to change notification settings - Fork 174
Allow Prefer: return=minimal for C(R)UD #133
Conversation
I think we should implement this now as it is more in line with PostgREST. Perhaps we do Small note: |
👍
|
How about just |
|
@steve-chavez could you please review this one? (Bobbie has exams this week) Is there value on adding an option It's not entirely clear to me some of the options from the PostgREST docs:
|
@kiwicopple Yes, that's something that's going to be corrected for PostgREST here: PostgREST/postgrest#1656. The Summarizing:
I think users of |
|
I think it's probably better to stick close to PostgREST as possible - if I'm looking up in the PostgREST docs Also I think making it a @steve-chavez it looks like you're thinking of naming it |
|
@kiwicopple I thought we wanted DX to prime over correctness for postgrest-js. After all So if we want correctness in this case, I think it'd be better to just focus on postgrest.from('users').insert({ username: 'bar' }, { return: 'minimal' })
// or representation(which is the default)
postgrest.from('users').insert({ username: 'bar' }, { return: 'representation' })
The
Yes, that's still not implemented, it could go either way really. Perhaps we should leave adding |
Definitely the case, which is why I don't want to add a boolean 😂. Reading the docs is part of a good DX and I think if our docs differ from PostgREST then it might lead to confusion. I don't mind making changes to the implementation but this minimal/representation as a boolean seems like big departure
yeah let's do it without the
Then finally, for making |
Got it. Missed that one. If we can make a breaking change here, how about changing the interface to this: // this is the default(return=minimal)
postgrest.from('users').insert({ username: 'bar' })
// this is return=representation
postgrest.from('users').insert({ username: 'bar' }).returning()
// kinda corresponds with the generated SQL as well, users would be more aware that requires SELECT privileges
// this would be the eventual return=headers
postgrest.from('users').insert({ username: 'bar' }).headers()This would go in line with the feedback on https://github.com/supabase/infrastructure/issues/391#issuecomment-733423540. Makes the operations more explicit, and it's easier to type. |
|
I'm not too deep in this topic, but I'd say it makes sense to default to what's most useful to the broadest audience, which I guess is Also, I like the approach of an options object as you had proposed earlier. postgrest.from('users').insert({ username: 'bar' }, { return: 'minimal' })
// or representation(which is the default)
postgrest.from('users').insert({ username: 'bar' }, { return: 'representation' })The options object can easily be typed and allows for easier changes/deprecation down the road 👍 Wdyt? |
Agree 👍. Let's stay with the
Yes. So let's keep the current default. It's not necessary to cause a breaking change for now. |
`Prefer return` is set to `representation` by default, but this gives an error when inserting/updating/deleting on, say, a write-only table. Allow the users to set it to `minimal` by setting `returnInserted`/`returnUpdated`/`returnDeleted`.
Co-authored-by: Steve Chavez <[email protected]>
|
Nice one team - agreed here. Let's ship it and we can #127 |
4136de4 to
da58def
Compare
|
🎉 This PR is included in version 0.22.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What kind of change does this PR introduce?
Feature.
What is the current behavior?
Prefer: returnheader is set torepresentationby default, but this gives an error when inserting/updating/deleting on, say, a write-only table.What is the new behavior?
Allow the user to set it to
minimalby settingreturnInserted/returnUpdated/returnDeleted.Additional context
Closes #127.
return=minimal/return=representationcould be a false dichotomy here, in which case it might be better to let the user setreturnto'minimal' | 'representation' | ..., but this is a safe bet for now I think.