Skip to content

Latest commit

 

History

History
59 lines (41 loc) · 2.06 KB

README.md

File metadata and controls

59 lines (41 loc) · 2.06 KB

NestJS with Drizzle ORM

This is an example/starter using the following stack:

  • NestJS
  • Drizzle ORM
    • Multiple schemas
    • Custom logger (with interpolated queries)
    • Example with reusable DAO
      • abstract.dao shows a way to abstract some reusable Drizzle ORM queries, e.g.,
        • getAll - get all entries for a specific entity
        • getById - get entries with specific id
        • getBySingleKey - get all entries with a specific value for the given key
  • PostgresSQL

It's an attempt (simple and concise) to show how to create multiple schemas using Drizzle ORM. Currently, Drizzle doesn't provide an easy way to do so.

Why do we want multiple schemas?

Sometimes for testing purposes we want to have the following schemas

  • test1 - Schema for test1
  • test2 - Schema for test2
  • ...
  • testN - Schema for testN

This way, we can run each test against a specific schema, so that, the tests are contained.

This might also be useful for a multi-tenant approach.


Install

npm i

Run

API

env DB_USER="drizzle-orm" env DB_PASSWORD="pass" env DB_HOST_NAME="localhost" env DB_PORT="5432" env DB_NAME="drizzle-orm" env DB_SCHEMA_NAME="schema_1" npm run start

Afterwards, open the following URL http://localhost:7979/api/jobs


Migrations

To have a better understanding about how migrations are set up, please see migrations README