jeudi 14 novembre 2019

Can I put all my application's database queries in a single Model file and require it on all pages?

I have a website with quite a few different queries involving Products, Users, Posts etc. On some pages, like the homepage, I need to return data from the database on all of these things.

At the moment I have database queries relating to Products in a /models/product.js file and then queries relating to blog Posts in a /models/post.js file. I then have to require all these on the home page to get data from those methods.

Is there anything against the MVC architecture, or general programming best practice for that matter, which would prevent me from putting all my database queries in a single Model file /models/db.js and just requiring that single file in all my files?

I am a newbie so if that sounds crazy please correct me.

Aucun commentaire:

Enregistrer un commentaire