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

Name mapping on post/put/patch #1773

Open
neilbmclaughlin opened this issue Mar 16, 2021 · 4 comments
Open

Name mapping on post/put/patch #1773

neilbmclaughlin opened this issue Mar 16, 2021 · 4 comments
Labels
enhancement a feature, ready for implementation

Comments

@neilbmclaughlin
Copy link

Just exploring postgrest and very impressed with it.

I like the name mapping ability as part of the get select syntax (e.g. select=contactId:contact_id). It means that an implementation detail (postgres column naming) doesn't leak into my code (I define my get url in configuration).

For posts the same isn't true (the post payload needs to use the column names) as I don't believe there is equivalent functionality for the columns parameter (e.g. columns=contactId:contact_id).

An example of where this might be useful is if I wanted to use Postgrest in development but another document store in production through configuration only and without having to adopt Postgres column naming conventions..

Is this something which has been considered?

Thanks in advance.

@wolfgangwalther wolfgangwalther added the enhancement a feature, ready for implementation label Mar 17, 2021
@wolfgangwalther
Copy link
Member

This is kind of related to #465 (comment), as well.

@steve-chavez
Copy link
Member

For this I think we'd need to process the json in a previous step to json_populate_record on our mutations queries.

The proposed query on #1567 (comment) could help with that.

@neilbmclaughlin
Copy link
Author

neilbmclaughlin commented Mar 25, 2021

After working with PostgREST a little more I've come to the conclusion that this feature should not be implemented.

I think the way to address the leaking of the Postgres column name format into application code is through the creation of REST specific schemas and the use of the AS clause in views within the isolated schemas as described in the schema isolation docs. The ability to GET and POST to the views means that JSON naming conventions can be maintained within the application code and column naming conventions can be maintained in Postgres.

I'd even suggest that the use of column renaming in select query parameters to address name format issues is an anti pattern but could be wrong on that.

@wolfgangwalther
Copy link
Member

I'd even suggest that the use of column renaming in select query parameters to address name format issues is an anti pattern but could be wrong on that.

I don't agree. I use renaming in two cases primarily:

  • Translating between snake_case in SQL and camelCase in JS. I really don't want to use camelCase in SQL, because then I would have to quote all those column names. Bah.
  • Renaming embeddings.

Allowing this for columns=..., too, seems like a natural extension to the current syntax to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement a feature, ready for implementation
Development

No branches or pull requests

4 participants