Should I build a view model in the code model layer or a view in the database? Should I build a view model in the code model layer or a view in the database?
Reply content:
Should I build a view model in the code model layer or a view in the database?
Better in Model
Looking at the needs and teams, if there is a dba, it will make the process more comfortable in the database, because a layer of logic is abstracted in the middle, if well designed, it can improve reusability.
After comparison, you will know.
On the model layer, developers can intuitively understand the view and modify it as needed.
Creating a view in a database simplifies the business logic, but maintaining the view requires additional effort.
In fact, it's like a model has a hook like afterSave beforeSave, and a database also has a trigger. Which of the following is better? The former is transparent and well maintained, while the latter simplifies the logic and is more efficient.
In addition, you need to consider that the view data of the databases you are using, such as oracle and sqlserver, is cached, and query from the view is much faster than query using the table connection, however, the view data of mysql is non-cached and does not improve the performance.