top | item 45677893

(no title)

sivers | 4 months ago

Whoa. How weird to see this on the HN front page. It's so not ready yet. I'll write up more about it some day soon.

For the big idea, see https://sive.rs/pg

I really took Rich Hickey's "Simplicity Matters" talk to heart. https://www.youtube.com/watch?v=rI8tNMsozo0

I've been making PostgreSQL-centered web apps for 9 years that way, by having PostgreSQL just return JSON. Then the "controller" (Ruby or whatever) parses the Mustache or ERB template with the JSON and returns HTML to the browser.

What I'm doing differently now is having PostgreSQL parse Mustache templates directly!

So now the controller just has to pass in the HTTP params, give it to the PostgreSQL function, and it returns HTML ready to return in the HTTP response.

discuss

order

jdmoreira|4 months ago

Hi Derek!

It's not new, my first job circa 2007 was working on a Delphi 7 desktop application and all the "business logic" was stored procedures in an Oracle db. It was early in my career but I believe this was fairly popular in the early 00s. I was too young to have an opinion but for sure others will remember and be able to add more colour to it.

Nice seeing you around here! I'm a fan.

sivers|4 months ago

Thanks! I do often get "YOU IDIOT!" type comments from people that did too many Oracle stored procedures in the 90s, and were burned by it.

But PostgreSQL is not Oracle and doing things this way has been working wonderfully for me for 9 years so far.

data_marsupial|4 months ago

In my first proper job, I worked with an accounting system in 2014/2015 that was a .NET GUI client that directly called SQL Server stored procedures. There was a bundled WMS that did the same thing. IIRC the requests were sent directly to the database and were authenticated with the client user's details.

I was a data analyst and had full access to the database for reporting and data import/export purposes. I had a lot of fun browsing through the stored procedures, which were not locked down or encrypted in any way, and figuring out how it all worked.

I even fixed a bug with a custom module that was causing huge stock valuation errors (I can't believe I even did this now) and also created my own automated order import procedure by monitoring the procedures used by the client's order import screen. Possibly invalidating warranties and support contracts etc. but no problems came of it. They even tried to rehire me a few years later.

miroljub|4 months ago

There's nothing wrong with it. Stored procedures, Java, Delphi, Ruby, Python, or whatever can be considered as a business logic layer separated from the data storage. Similarly, you consider your Python controller business layer separate from the web UI frontend.

And if you complain that stored procedure language is not so versatile for the business logic, remember that people have been using far worse languages for that, like COBOL, MUMPS, ColdFusion, ...

hatefulheart|4 months ago

Despite reading the README and the article I am still unclear about how these templated values are populated. So presumably we store our HTML on the sql server along with some templating syntax then how do we plug that value so to speak?

Secondly, what do we do about things like HTML fragments à la HTMX / Datastar hypermedia approach? Do we just hit the DB for 10 lines of HTML to populate the next card in a multi step form?

sivers|4 months ago

I edit my HTML templates in the templates/ directory.

Then I use this little Ruby script to sync them into the database, which is where they're actually used:

https://github.com/sivers/sivers/blob/master/scripts/templat...

I haven't done HTMX fragments yet. This repository is quite new, and only like 5% done.

arunaugustine|4 months ago

For someone who wants to tread this path, using postgreSQL stored procedures in a team settings, what would be a good dev workflow in a team. Update them in git and use a CI to update the DB etc? Is there some tips that you can share on that?

danielcberman|4 months ago

Have you crossed paths with Chris Dancy? He’s been doing something similar with a life database using Airtable. https://www.chrisdancy.com/howto

chrisweekly|4 months ago

Great link, Chris Dancy's experiences and relationship to tech are very interesting.