Generic CRUD or Sqls specifics

Asked

Viewed 104 times

7

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

  1. create a generic CRUD? or
  2. 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, but has the disadvantage of not knowing previously the available Sqls and not providing complex queries. The 2nd approach has the advantage of simplicity, the ability to be specific, and the disadvantage of having to rewrite the code of simple queries.

What would be the best approach to the situation outlined?

1 answer

5


The best approach always depends on the goal set on the horizon.

The development model based on the creation of Cruds will always take advantage of the speed of development, considering that many things are done in automatic. The approach is worthwhile because it is not every system that is entirely complex. In most cases, systems follow the good old Pareto Principle, in which 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 artisanal, ie made sentence by sentence.

Even when the system has a trend of continuous development, the second approach is more interesting at the time when performance problems are felt. It’s that moment in the code lifecycle where screens and actions that were once fast start to slow down. There it is worth studying the execution plan of the sentences, rewrite the code seeking optimization, and so on.

Still, in the current stage of object-relational mapping-based frameworks (the famous Orms), the idea is precisely that the framework itself does a prior optimization work, freeing the development team to spend time on optimization at an early stage of development.

  • then the second solution (simpler, but more time consuming) would be the most appropriate because it is more readable and efficient (in performance).

  • In a second development moment, as the system becomes complex, yes, but there’s no reason to have that at the beginning of development.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.