Skip to content

Latest commit

 

History

History
33 lines (28 loc) · 2.21 KB

File metadata and controls

33 lines (28 loc) · 2.21 KB
  • SQL: Structured Query Language used to communicate with relational databases. It defines actions like querying data, inserting records, updating records, and deleting records.
  • PostgreSQL: An open-source relational database management system (RDBMS) that processes SQL commands and manages data. It performs the actual work of storing, retrieving, and managing data.
  • NeonDB: A serverless platform built on top of PostgreSQL. It abstracts away infrastructure management, providing features like autoscaling, branching, and point-in-time restore. It offers a more modern and managed experience while still using PostgreSQL as the underlying database engine.
  • Drizzle: A lightweight TypeScript ORM that simplifies and type-safes interactions with SQL databases. It allows you to define your schema, generate and apply migrations, and write type-safe queries. Drizzle can be used with NeonDB to interact with your PostgreSQL database in a more developer-friendly manner.

Workflow with Drizzle:

  1. Define Schema: Use Drizzle to define your database schema in TypeScript.
    import { pgTable, serial, text, doublePrecision } from 'drizzle-orm/pg-core';
    
    export const products = pgTable('products', {
      id: serial('id').primaryKey(),
      name: text('name'),
      description: text('description'),
      price: doublePrecision('price'),
    });
  2. Generate Migrations: Run the Drizzle command to generate migration files based on your schema changes.
    drizzle-kit generate --schema=./src/index.ts --dialect=pg
  3. Apply Migrations: Apply the generated migration files to your database.
    drizzle-kit migrate --dialect=pg

Drizzle's Role:

  • Type Safety: Ensures that your database queries are type-safe, reducing the risk of runtime errors.
  • Schema Management: Allows you to easily manage and evolve your database schema using TypeScript.
  • Integration: Works with NeonDB (and other PostgreSQL environments) to provide a more streamlined and developer-friendly experience.

By using Drizzle, you can simplify and type-safe your interactions with your PostgreSQL database managed by NeonDB, making it easier to handle schema changes and write queries.