News for hackers. Stuff that matters.
Re:SPAs Were a Mistake by int_19h on Thursday March 03, 2022 @01:33AM (#30537858)
What I really don't get is why we don't just expose SQL directly at this point. Is it just security? Database servers have fairly extensive authentication and authorization models.
Re:SPAs Were a Mistake by littlecranky67 on Thursday March 03, 2022 @03:03AM (#30538378)
Authorization & access restrictions. Yes, you can go quite far with table/row/column permissions, but a lot of business logic cannot be modeled using just those (i.e. "user cannot place orders if total outstanding invoice payments surpass value $X").
Re:SPAs Were a Mistake by dragonwriter on Thursday March 03, 2022 @05:08AM (#30539188)
The combination of DB permissions, DB constraints, and simple (SQL, not procedural language) triggers gets you a lot, including the ability to enforce rules like the one you mention.
Re:SPAs Were a Mistake by littlecranky67 on Thursday March 03, 2022 @06:24AM (#30539617)
Yes, you can enforce a lot through SQL triggers/stored procedures etc. But you often end up abusing your DB/SQL as a business logic layer, where your business logic is encoded in a huge set of row/column permission and custom SQL triggers . This tightly couples your database into your whole business application stack.

Especially in Oracle PL/SQL, I've seen this often abused to an extend where no one ever understood the whole business logic anymore (as logic was spread out in frontend, middle-layer services, and DB mumbojumo), and the database became a fragile core-piece (with a significant vendor login) and hindered all sort of future development.

Seriously, your business logic should be modelled in code, ideally in some sort of service layer (which does not necessarily mean microservices!).

Re:SPAs Were a Mistake by dragonwriter on Thursday March 03, 2022 @10:20AM (#30542149)
> But you often end up abusing your DB/SQL as a business logic layer, where your business logic is encoded in a huge set of row/column permission and custom SQL triggers.

That's not “abuse”. Admittedly, it's no longer an essential best practice for most systems, the way it used to be viewed, because it's more common to have a single application which fully owns the database and not to (at least in idealized theory, though very some ops staff still end up with direct access to the prod DB) allow access by other means, so in theory it doesn't tend to be necessary to avoid either circumvention of rules or (inevitably inconsistent, as well as expensive to maintain) duplication of logic.

Re:SPAs Were a Mistake by int_19h on Thursday March 03, 2022 @04:57AM (#30539128)
Then why aren't we working on improving the databases to allow for such complex rules, and instead wrap it in another layer (often multiple) to do all this stuff there?
Re:SPAs Were a Mistake by littlecranky67 on Thursday March 03, 2022 @06:25AM (#30539622)
because a database should not hold your business logic. It should hold your data, and that it can do well. See also my other post on parent for more reasoning.
Re:SPAs Were a Mistake by funcDropShadow on Thursday March 03, 2022 @09:50AM (#30541735)
I beg to differ in many interesting cases, we put at least some parts of the business logic into the database. The table design is a direct consequence of the business logic, the same is true for constraints and triggers.
Re:SPAs Were a Mistake by int_19h on Thursday March 03, 2022 @06:36PM (#30548580)
Why shouldn't it? As noted above, database servers already have most of this (security) logic in them - likely tested much better than whatever you can write on top of the database yourself. And given how many apps are basically just CRUD, why reinvent the wheel every time?
Re:SPAs Were a Mistake by yencabulator on Saturday March 05, 2022 @11:52AM (#30569139)
Mostly because the tooling is so bad. Or do you have unit tests, lint, and easy version control for your stored procedures? Are they written in a way that matches at all what rest of your programming is? Can you import a randomly picked utility library?
Re:SPAs Were a Mistake by int_19h on Saturday March 05, 2022 @08:34PM (#30574081)
The next obvious question is, why is tooling so bad then? And would it have been so bad if we invested as much into RDBMS as we did into Node.js web-frameworks-of-the-day.
Re:SPAs Were a Mistake by yencabulator on Sunday March 06, 2022 @09:34PM (#30583591)
Writing the next modern elegant artisanal javascript webshit is a lot easier than making a sandboxed programming environment that integrates tightly with a production quality database engine and has a good story for testing, deployment, debugging, etc.
Re:SPAs Were a Mistake by qw on Thursday March 03, 2022 @04:29AM (#30538967)
Even if you solve the security issue, a query can easily bring down the server if it has a complex join query.

This could be solved by only exposing stored procedures, but that just moves the code to the database server instead of the REST service with the same problems as before.

Re:SPAs Were a Mistake by tored on Thursday March 03, 2022 @05:33AM (#30539343)
You can also use a VIEW.

How does GraphQL make sure to respect table indexes? If not you get a super slow query.

Re:SPAs Were a Mistake by qw on Thursday March 03, 2022 @05:56AM (#30539473)
You can still get performance issues with a view if you "select *" on a large amount of data, or join with other views. By exposing the SQL to a web page, you also open up for DDoS attacks more easily, as you can write complex SQL queries

You can get the same problems with GraphQL or stored procedures too of course, if the queries are not optimized correctly

Re:SPAs Were a Mistake by MonaroVXR on Thursday March 03, 2022 @10:38PM (#30550411)
So what's the solution to this?
Re:SPAs Were a Mistake by int_19h on Friday March 04, 2022 @12:41AM (#30551093)
Performance quotas.
Re:SPAs Were a Mistake by tekknik on Thursday March 03, 2022 @07:22PM (#30548914)
Because a human is writing the resolvers pulling the data from the database. Set whatever index you want to use.
Re:SPAs Were a Mistake by tored on Thursday March 03, 2022 @04:13AM (#30538872)
Just give the end user an account to phpMyAdmin. Done. No complex frontend framework required.
Re:SPAs Were a Mistake by littlecranky67 on Thursday March 03, 2022 @06:32AM (#30539652)
You wouldn't belive how often companies use excel with external datasources like this. Excel basically is the common-ui for a lot of people.

And most of the projects I worked on in my professional career as a webdev, were replacing such workflow with a proper web application, because excel does not scale and eventually people fuckup their data.