News for hackers. Stuff that matters.
Re:PostgreSQL example of self-contained stored procedures by tyingq on Sunday October 27, 2019 @10:18AM (#21369826)
It's "cheating" a bit, but Postgrest is interesting in this space: https://github.com/PostgREST/postgrest
Re:PostgreSQL example of self-contained stored procedures by krueger71 on Tuesday October 29, 2019 @03:00AM (#21384767)
Yes definitely. I was involved in a project where we used Postgrest on top of a layered database. Postgrest served an api-schema consisting only of views where some had instead-of triggers needed for updates and inserts of data. Some functions and procedures were also present in the api-schema. The tables were kept in a separate data-schema and considered a private implementation detail in the same way one would do it with a more traditional architecture. During development we used tools like https://sqitch.org/ and https://pgtap.org/ to do schema-evolution and unit-testing.

The reason for these architectural choices was that we had a need to connect database-only clients such as https://qgis.org/ as well as web-front ends and wanted to route all requests and updates through the same logic. I think it worked out quite well. We were able to do quite heavy https://postgis.net/ lifting in the views with good performance.

Of course the tooling feels rather primitive during editing, but the round-trip and deployment is fast. Unit tests run faster than you might expect even with rollbacks and loading of test data between each test.

Re:PostgreSQL example of self-contained stored procedures by llimllib on Sunday October 27, 2019 @10:24AM (#21369865)
yes! I've seen that and I'm considering writing some sort of similar postgres -> protobuf layer so that I can automatically generate my grpc structs from postgres enums.

Right now a pain point for us is that we have a generated database layer, a generated protobuf layer, and we have to do lots of fiddly manual database -> grpc struct translations. Too easy to get off-by-one errors (because you usually need a null enum element in protobuf that you don't need in postgres, particularly)