by stefanchrobot · 7y ago · 0 comments
That's what VIEWs are for! Well, one use-case of VIEWs, anyways.
There's nothing wrong with the schema as the API since you can use VIEWs to maintain backwards compatibility as you evolve your product.
Put another way: you will have an API, you will need to maintain backwards compatibility. Not exposing a SQL schema as an API does not absolve you or make it easier to be backwards-compatible.
You might argue that you could have server-side JSON schema mapping code to help with schema transitions, and, indeed, that would be true, but whatever you write that code in, it's code, and using SQL or something else is just as well.
Both automatically updatable views (supporting insert/update/delete by default because their structure provides a clean mapping to the backing table) and views made updatable through instead-of triggers exist in Postgres.
CREATE TRIGGER <name>
INSTEAD OF INSERT OR UPDATE OR DELETE
ON <view-name> ..More realistically, stored procs would do the CUD parts.
You can, and there is no reason you shouldn't.
> More realistically, stored procs would do the CUD parts.
Why are stored procs more realistic?
Shouldn't? Why?
We have quite large amount of data (100TB+ and trillions of rows at this point [0]) and no problem with views.