postgrest
postgrest copied to clipboard
Add underscore equality operator to filter using keys in the request body
WIP - Needs more discussion
Using this idea https://github.com/PostgREST/postgrest/issues/2125#issuecomment-1200054135, the underscore operators will filter using the keys in the body. This PR implements the following:
- The
_eq
operator to verify for equality with items in the body - Support to select any identifier in the body (not only PKs). This gives more freedom in the case of bulk updates, e.g.:
PATCH /user?is_active=_eq.is_active HTTP/1.1 [ { "username": "userA", "is_active": true }, { "username": "userB", "is_active": false } ]
- Full table updates are allowed once again, addressing this issue: https://github.com/PostgREST/postgrest/pull/2195#discussion_r932946412
Wait, the comment in https://github.com/PostgREST/postgrest/issues/2125#issuecomment-1200054135 says:
Underscore operators could be used to operate on columns besides referencing values on the request body. This would allow doing https://github.com/PostgREST/postgrest/issues/1105#issuecomment-395238192 without computed columns:
SEARCH /PredictedGenes?Strand=eq.+&GeneStart=_gt.GeneEnd
Operating on a body value would still be allowed, body would be a reserved identifier:
SEARCH /PredictedGenes?Strand=_eq.body->strand&GeneStart=_lt.GeneEnd { "Strand": "-"}
With the implementation in this PR, the ability to do column to column matches will be lost, right?
With the implementation in this PR, the ability to do column to column matches will be lost, right?
Yes. It was one of the reasons I turned this into a draft for now. It should use a syntax like ?col=_eq.$.col
to get filters from the body and allow column matches too.