Another way speaking, given me a well designed SQL database, i could produce a working software in one day, with bad code even.
Most of broken code is because of wrongly designed database, not the code itself.
Another way speaking, given me a well designed SQL database, i could produce a working software in one day, with bad code even.
Most of broken code is because of wrongly designed database, not the code itself.
Often, coders receive a design of Database from leaders, with SQL store procedures.
Only then they will follow the mock-up and then start to code.
My point of view is that, it's not worth the trade-off here (especially you have only limited time-budget or dev-budget).
The point of Dependency Inversion is that your business code doesn't know it's talking to a database.
Code is clean, no more layered abstraction for no purpose.
I agree with this.
> i query by writing directly SQL code, instead of using ActiveRecord
I haven't used ActiveRecord, but I'm sure I'd hate it and prefer direct SQL - if I were forced to choose between the two.
So let me offer a third choice: an abstraction which serves an actual purpose, and is neither raw SQL nor ActiveRecord.
Pretend your domain is about farming fruit. A naive design might be:
FruitService -> FruitDatabase.
The DI way is to change that to:
FruitService -> Fruit <- FruitDatabase
You effectively divide-and-conquer the problem, so that you can think about your fruity business rules in the Service, and think about fruity storage in the Database.
When working in the Service, your might think about business thoughts like "We should throw away the 25% smallest green apples".
When working in the Database, you might think "Do I like the amount of SQL normalisation? Did I miss any indexes? How do I model an apple at the SQL table level?"
The purpose of this is to prevent you from thinking "Do I have an SQL column for colour?" when you're working on the business rules.
http request => controller => params manipulation => sql => database.
My comment is generic about storage implementation though. The same story applies to NoSQL or any other kinds of database as well.
Apparently a quote from Linus, but I think it holds true for almost every level of the stack.