Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

drizzle-orm

Package Overview
Dependencies
Maintainers
4
Versions
924
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

drizzle-orm

Drizzle ORM package for SQL databases

  • 0.35.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
564K
increased by6.64%
Maintainers
4
Weekly downloads
 
Created

What is drizzle-orm?

Drizzle ORM is a TypeScript-first ORM for Node.js that focuses on type safety, performance, and simplicity. It provides a fluent API for defining and querying your database schema, making it easier to work with SQL databases in a type-safe manner.

What are drizzle-orm's main functionalities?

Schema Definition

Drizzle ORM allows you to define your database schema using a fluent API. This makes it easy to create and manage your database tables with type safety.

const { defineSchema, types } = require('drizzle-orm');

const schema = defineSchema({
  users: {
    id: types.int().primaryKey().autoIncrement(),
    name: types.string().notNull(),
    email: types.string().unique().notNull()
  }
});

Query Building

You can build and execute SQL queries using a fluent API. This example demonstrates how to select users with the name 'John Doe'.

const { select } = require('drizzle-orm');

const users = await select(schema.users)
  .where(schema.users.name.eq('John Doe'))
  .execute();

Type Safety

Drizzle ORM ensures type safety throughout your database operations. This example shows how to insert a new user into the users table with type-checked values.

const { insert } = require('drizzle-orm');

await insert(schema.users).values({
  name: 'Jane Doe',
  email: 'jane.doe@example.com'
}).execute();

Migrations

Drizzle ORM supports database migrations, allowing you to evolve your database schema over time. This example demonstrates how to create and drop a 'posts' table.

const { migrate } = require('drizzle-orm');

await migrate(schema, {
  migrations: [
    {
      up: async (db) => {
        await db.schema.createTable('posts', {
          id: types.int().primaryKey().autoIncrement(),
          title: types.string().notNull(),
          content: types.text().notNull(),
          userId: types.int().references(schema.users.id)
        });
      },
      down: async (db) => {
        await db.schema.dropTable('posts');
      }
    }
  ]
});

Other packages similar to drizzle-orm

Keywords

FAQs

Package last updated on 21 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc