8

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 ]
  • 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

  1. How do I create models without ORM or ODM.
  2. Is there a difference between schema and model ?
  3. Writing sql functions in model folder : is that the right way to use this architectural pattern.
  4. If schema/model is created in models folder then where do the sql queries reside ?

What I have tried?

  1. For validating objects with required keys from res.body object
codesim
  • 111
  • 7

0 Answers0