title: Creating a model in nodejs without an ORM or ODM
body: <p>I am surprised why this is so hard to find.</p>
  
  <p>I am trying to convert my monolith to a 3 layer architecture for my node express app with a propriety sql.</p>
  
  <h2>Repository</h2>
  
  <p><strong>BEFORE</strong> architecture change 
  1 file entry.js
  1 endpoint with business logic
  Functions with raw sql that are called after validation of res.body objects</p>
  
  <p><strong>AFTER</strong></p>
  
  <ul>
  <li> backend
  
  <ul>
  <li> src
  
  <ul>
  <li> services
  
  <ul>
  <li> service1</li>
  </ul></li>
  <li> routes
  
  <ul>
  <li> service1Route [ Route handling /service1 from entry.js ] </li>
  </ul></li>
  <li> models
  -service1Model [ Contains sql functions, not schema ]</li>
  </ul></li>
  </ul></li>
  <li> entry.js  [ Main express app]</li>
  </ul>
  
  <p><strong>Tech used</strong> 
   - Using .js not .ts
   - nodejs 
   - express
   - </p>
  
  <p><strong>Constraints</strong> 
   - I cannot use postgres or sequlize as they don't support the propriety db that I am using.</p>
  
  <h2>Assumptions</h2>
  
  <ul>
  <li>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.</li>
  <li>Now I want to create my own models / schema with such validations. </li>
  </ul>
  
  <h2>Ask</h2>
  
  <ol>
  <li>How do I create models without ORM or ODM.</li>
  <li>Is there a difference between schema and model ?</li>
  <li>Writing sql functions in model folder :  is that the right way to use this architectural pattern.</li>
  <li>If schema/model is created in  models folder then where do the sql queries reside ?</li>
  </ol>
  
  <h2>What I have tried?</h2>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/17781472/how-to-get-a-subset-of-a-javascript-objects-properties">For validating objects with required keys from res.body object</a> </li>
  </ol>