mhacks-web
mhacks-web copied to clipboard
RFC: Breakup models into separate files (methods, query, etc.)
RFC: Breakup models into separate files (methods, query, etc.)
Issue:
The model files are prone to getting much larger due to how all central processing is conducted within them.
Resolution:
Separate the models into different files under a server/db/model/ModelName/
directory that contains a methods.js
, query.js
, etc. Each of these files would export a function that accepts a mongoose.Schema
object and appends the methods, query, etc. functions as needed.
The actual model file would then require these functions and apply them after the schema definition, passing that down to each.
Comments:
What are your thoughts on this strategy? Inherent pros/cons? Complexities that are introduced? etc.