balena-io / pinejs

Generate rest APIs from natural language models
Apache License 2.0
63 stars 11 forks source link

Add support for upserts based on natural keys #125

Open thgreasi opened 6 years ago

thgreasi commented 6 years ago

It would be great if we could do an upsert for a resource using its unique properties as a key. We are currently limited to POSTing and then PATCHing when erroring with a unique key constrain violation. For example, for a resource where <col1> & <col2> are a unique pair, we would want to make an upsert to insert or update a record containing a note, by sending a request containing <col1: X>, <col2: Y> and <note: Z>.

Additionally, it would be great to have these upserts work as part of batch operations as well.

See: https://github.com/resin-io/resin-api/issues/765

Page- commented 4 years ago

This is available via PUT but it does set any non-specified fields back to defaults - I think there's value in a version that does not reset defaults as well

thgreasi commented 4 years ago

Do the fields in the id field also have to be in the body of the POST @Page-? Maybe an example curl or pinejs-client one would be even better and good for future reference.