I am surprised why this is so hard to find.
I am trying to convert my monolith to a 3 layer architecture for my node express app with a propriety sql.
Repository
BEFORE architecture change 1 file entry.js 1 endpoint with business logic Functions with raw sql that are called after validation of res.body objects
AFTER
- backend
- src
- services
- service1
- routes
- service1Route [ Route handling /service1 from entry.js ]
- models -service1Model [ Contains sql functions, not schema ]
- services
- src
- entry.js [ Main express app]
Tech used - Using .js not .ts - nodejs - express -
Constraints - I cannot use postgres or sequlize as they don't support the propriety db that I am using.
Assumptions
- postgres or mongoose have popular ORMs and ODMs without which you cannot use them hence developers are ( as a good practice ) forced to create models.
- Now I want to create my own models / schema with such validations.
Ask
- How do I create models without ORM or ODM.
- Is there a difference between schema and model ?
- Writing sql functions in model folder : is that the right way to use this architectural pattern.
- If schema/model is created in models folder then where do the sql queries reside ?