generic CRUD or specific SQLs

7

In a system that tends to grow in number of classes and users, what would be the best approach to working with database access?

  • create a generic CRUD? or
  • create specific methods to insert and update each model class that is persisted in the database?
  • In my view the first approach has the advantage of writing only once the code to insert and remove and others, however it has the disadvantage of not knowing in advance the available SQLs and of not providing complex queries. The second approach has the advantage of simplicity, the ability to be specific, and the disadvantage of having to rewrite the simple query code.

    What would be the best approach for this situation?

        
    asked by anonymous 09.04.2015 / 15:10

    1 answer

    5

    The best approach always depends on the horizon goal.

    The development model based on the creation of CRUDs will always take advantage of the speed of development, considering that many things are done automatically. The approach is worth it because it is not every system that is entirely complex. In most cases, the systems follow the good Old Pareto Principle , where 80% of performance bottlenecks are concentrated in up to 20% of code . In these cases, there are no big gains when the production of code is handmade, that is, sent to sentence.

    Even when the system has a continuous developmental tendency, the second approach is more interesting at a time when performance problems are felt. It is that moment in the code life cycle in which screens and actions that were fast before began to become slow. It's worth studying the sentence execution plan, rewriting the code for optimization, and so on.

    However, in the current stage of frameworks based on object-relational mapping (the famous ORM's), the idea is precisely that the framework itself does a previous optimization work, freeing the development team to spend time with optimization at an internship development.

        
    09.04.2015 / 17:07