4 ms·
>No it isn't. Most popular web frameworks expect to be used with an ORM and will autogenerate CRUD queries, while providing minimal if any support for more comp
by corethree 3y ago
>No it isn't. Most popular web frameworks expect to be used with an ORM and will autogenerate CRUD queries, while providing minimal if any support for more complex queries with logic in them.
Or a query builder. Whether you use the ORM or query builder to build the queries or you manual build it is up to you. That's exactly my point. These queries aren't "autogenerated" you're writing a query in your web application with primitives decided by the framework and the ORM and then it's getting compiled into a SQL query with SQL primitives that's it. It's the same thing. I don't know what you're negating here, you're basically regurgitating exactly what I said.
>They do, but they use those SQL databases like a key value store - read/write by primary key most of the time, with occasional relationships but nothing fancier than that (e.g. no aggregations).
Wrong. A SQL database is more like an array. Things are stored in memory one after the other. That is the default. You can then choose an index, and have pointers to sections of the array that can make it havethe speed of your typical hash map or n-ary search tree. There is a huge amount of logic being thrown into IO.
- lmm 3y ago> I don't know what you're negating here You said "As much logic that can be pushed to the database as possible" and that's simply not true. The normal, mainstream way (like it or not) is to use the database as a dumb store and have the business logic in the application layer. > A SQL database is more like an array. Things are stored in memory one after the other. That is the default. You can then choose an index, and have pointers to sections of the array that can make it havethe speed of your typical hash map or n-ary search tree. There is a huge amount of logic being thrown into IO. None of that is business logic. It's implementation details at best.
- corethree 3y ago>You said "As much logic that can be pushed to the database as possible" and that's simply not true. The normal, mainstream way (like it or not) is to use the database as a dumb store and have the business logic in the application layer. False. What I said is true. As much as possible is 100% true. There are some things that have to live in the business layer. But as much as possible should be pushed to the database. All the "business layer" does is build the correct query. What you're describing is multiple queries The web application has to fetch data, do "business logic" then fetch or update data again. That is both slow and inefficient, but sometimes necessary. As much as possible the web application needs to build the query and do everything in a single IO call. The round trip time and even simply initializing multiple queries on the database side is magnitudes slower then one query that does the full operation. Business logic should be extremely thin. This idea of a dumbstore is highly misguided. No framework works like this. The database is the workhorse of the basic web application, the application layer is suppose to be the thinnest layer. Your ORM, query builder or SQL code is where most of the logic real should lie. >None of that is business logic. It's implementation details at best. False again. The basic SQL query is this: SELECT <COLUMNS> FROM <TABLE> that is list retrieval at an API level and Not just implementation details. A key value store looks like this: VALUE = MAP[KEY] Understand? There is no equivalent of key value fetching in SQL, you basically have to filter that list with SELECT * FROM TABLE WHERE id = ... You can imitate a key value store both at the implementation level and at the API level if you use a hash index on a unique id like in the example query I just mentioned, but that is not the primary mode of the SQL api. I don't think you get it.
- prmph 3y ago> False. What I said is true. As much as possible is 100% true. There are some things that have to live in the business layer. But as much as possible should be pushed to the database. All the "business layer" does is build the correct query. I think you are wrong, the other commenter is correct. In all my years of engineering, I rarely see a lot of business logic in the database. Note that we are talking about what the situation _is_, not what it should be. It is an eternal debate as to whether it is better to push as much login into the Db as possible. My own view is that you should use the right tool for the job. Databases, excel at, well, managing data. Regular languages excel at logic. > Business logic should be extremely thin. I'm leading a team building a front end to statistical engines, storing metadata in the Db. Are you suggesting we should implement the higher level statistical functions in the Db?
- corethree 3y agoYour talking about the multitudes of architectures that stem from the core model. I'm talking about the core model. Which is crud. The core model of a typical website is mainly updates to central state with little compute. Think nodejs server paired with a typical SQL database. The very reason nodejs exists is based on this core assumption of web: low compute and non blocking high io workflows. You're talking about heavy compute... then that deviates from the core model. With heavy compute it turns more into a queue with workers. That is not the core architecture of the web. It's more of popular and important system that exists in conjunction with the core. That is what your statistical function implies. If your stats function is simple and trivial, then you can indeed possibly achieve orders of magnitude of speed up if you offload that trivial calculation to the database.
- lmm 3y ago> Business logic should be extremely thin. > This idea of a dumbstore is highly misguided. No framework works like this. The database is the workhorse of the basic web application, the application layer is suppose to be the thinnest layer. Your ORM, query builder or SQL code is where most of the logic real should lie. Like it or not, all the big mainstream web frameworks are oriented towards having the business logic in the application layer. Again, look at what kind of querying the ORM supports. > The basic SQL query is this: SELECT <COLUMNS> FROM <TABLE> that is list retrieval at an API level and Not just implementation details. A key value store looks like this: VALUE = MAP[KEY] Understand? > There is no equivalent of key value fetching in SQL, you basically have to filter that list with SELECT * FROM TABLE WHERE id = ... If you look at the ORM APIs and the way mainstream web frameworks use them, fetching an object by primary key is very much the primary supported way of using them. MySQL even added the option of querying via the memcached protocol after their benchmarks showed that for typical web services it was taking 3x as long to parse the SQL as actually running the query.