Convert Figma logo to code with AI

drizzle-team logodrizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅

29,581
966
29,581
1,678

Top Related Projects

30,047

Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i.

35,618

ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

42,699

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB

19,894

A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, MS SQL Server, PostgreSQL and SQLite/libSQL databases.

A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js

Quick Overview

Drizzle ORM is a lightweight and type-safe TypeScript ORM for SQL databases. It provides a simple and intuitive API for database operations, with a focus on performance and developer experience. Drizzle ORM supports multiple database engines, including PostgreSQL, MySQL, and SQLite.

Pros

  • Strong TypeScript support with full type inference
  • Lightweight and performant, with minimal overhead
  • Flexible query building with a fluent API
  • Support for multiple database engines

Cons

  • Relatively new project, may lack some advanced features of more established ORMs
  • Limited ecosystem and community resources compared to larger projects
  • Learning curve for developers used to traditional ORM patterns

Code Examples

  1. Defining a schema:
import { pgTable, serial, text, integer } from 'drizzle-orm/pg-core';

const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
  age: integer('age')
});
  1. Performing a simple query:
import { eq } from 'drizzle-orm/expressions';

const result = await db.select().from(users).where(eq(users.id, 1));
  1. Inserting data:
const newUser = await db.insert(users).values({
  name: 'John Doe',
  age: 30
}).returning();
  1. Joining tables:
const posts = pgTable('posts', {
  id: serial('id').primaryKey(),
  title: text('title').notNull(),
  authorId: integer('author_id').references(() => users.id)
});

const result = await db.select({
  userName: users.name,
  postTitle: posts.title
})
.from(users)
.leftJoin(posts, eq(users.id, posts.authorId));

Getting Started

  1. Install Drizzle ORM and the database driver:
npm install drizzle-orm pg
npm install -D drizzle-kit
  1. Define your schema:
import { pgTable, serial, text, integer } from 'drizzle-orm/pg-core';

export const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
  email: text('email').notNull()
});
  1. Create a database connection and query:
import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';
import { users } from './schema';

const pool = new Pool({
  connectionString: 'postgres://user:password@host:port/db'
});

const db = drizzle(pool);

const result = await db.select().from(users);
console.log(result);

Competitor Comparisons

30,047

Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i.

Pros of Sequelize

  • Mature and widely adopted ORM with extensive documentation and community support
  • Supports multiple databases (MySQL, PostgreSQL, SQLite, and more)
  • Offers advanced features like migrations, associations, and transactions

Cons of Sequelize

  • Steeper learning curve due to its extensive feature set
  • Can be slower for complex queries compared to raw SQL
  • Larger bundle size and potential performance overhead

Code Comparison

Sequelize

const User = sequelize.define('User', {
  name: DataTypes.STRING,
  email: DataTypes.STRING
});

const users = await User.findAll();

Drizzle ORM

const users = db.select().from(usersTable);

Key Differences

  • Drizzle ORM focuses on type safety and simplicity, while Sequelize offers a more feature-rich ecosystem
  • Drizzle ORM uses a more SQL-like syntax, making it easier for developers familiar with SQL
  • Sequelize provides built-in validation and hooks, which are not present in Drizzle ORM
  • Drizzle ORM has a smaller learning curve and is more lightweight compared to Sequelize

Use Cases

  • Choose Sequelize for complex applications requiring extensive ORM features and multi-database support
  • Opt for Drizzle ORM in TypeScript projects prioritizing type safety and simpler database operations

Both ORMs have their strengths, and the choice depends on project requirements, team expertise, and performance considerations.

35,618

ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

Pros of TypeORM

  • More mature and widely adopted, with a larger community and ecosystem
  • Supports a broader range of databases, including MongoDB and SQL databases
  • Offers more advanced features like migrations, relations, and cascades

Cons of TypeORM

  • Heavier and more complex, with a steeper learning curve
  • Can be slower in some scenarios due to its ORM nature and additional abstractions
  • Requires more boilerplate code for setup and configuration

Code Comparison

TypeORM:

@Entity()
class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;
}

Drizzle ORM:

const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name'),
});

Summary

TypeORM is a more established and feature-rich ORM with support for various databases and advanced functionalities. However, it comes with increased complexity and potential performance overhead. Drizzle ORM, on the other hand, offers a simpler and more lightweight approach, focusing on type safety and performance. The choice between the two depends on project requirements, team expertise, and performance considerations.

42,699

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB

Pros of Prisma

  • More mature ecosystem with extensive documentation and community support
  • Powerful schema migration and database introspection capabilities
  • Built-in type safety and auto-generated TypeScript types

Cons of Prisma

  • Steeper learning curve due to its custom query language (Prisma Client)
  • Heavier runtime dependency and potential performance overhead
  • Less flexibility in raw SQL queries and database-specific features

Code Comparison

Prisma:

const user = await prisma.user.create({
  data: { name: 'Alice', email: 'alice@example.com' },
})

Drizzle ORM:

const user = await db.insert(users).values({
  name: 'Alice',
  email: 'alice@example.com',
}).returning();

Both Prisma and Drizzle ORM are TypeScript-first ORMs, but they differ in their approach to database interactions. Prisma offers a more abstracted, schema-driven approach with its own query language, while Drizzle ORM provides a more SQL-like syntax and lighter runtime footprint. Prisma excels in complex scenarios and large-scale applications, whereas Drizzle ORM offers simplicity and closer-to-SQL operations, making it potentially easier for developers familiar with raw SQL.

19,894

A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.

Pros of Knex

  • More mature and widely adopted, with a larger ecosystem and community support
  • Supports a broader range of databases, including PostgreSQL, MySQL, SQLite, and Oracle
  • Offers more advanced features like migrations, seeds, and connection pooling out of the box

Cons of Knex

  • Less type-safe compared to Drizzle ORM's TypeScript-first approach
  • Query building can be more verbose and less intuitive for complex queries
  • Performance may be slightly lower due to its more generic approach to database support

Code Comparison

Knex query example:

knex('users')
  .select('name', 'email')
  .where('age', '>', 18)
  .orderBy('name', 'desc')
  .limit(10)

Drizzle ORM query example:

db.select({
  name: users.name,
  email: users.email,
})
  .from(users)
  .where(gt(users.age, 18))
  .orderBy(desc(users.name))
  .limit(10)

Both Knex and Drizzle ORM are powerful query builders and ORMs, but they cater to different needs. Knex is more established and versatile, supporting multiple databases with advanced features. Drizzle ORM, on the other hand, focuses on providing a type-safe, performant solution primarily for TypeScript users, with a more intuitive query-building syntax. The choice between the two depends on project requirements, database support needs, and developer preferences for type safety and query-building style.

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, MS SQL Server, PostgreSQL and SQLite/libSQL databases.

Pros of MikroORM

  • More mature and feature-rich ORM with a larger ecosystem
  • Supports a wider range of databases and query types
  • Offers advanced features like entity relationships and lazy loading

Cons of MikroORM

  • Steeper learning curve due to its complexity and extensive features
  • Heavier and potentially slower for simple use cases
  • Requires more setup and configuration compared to Drizzle ORM

Code Comparison

MikroORM:

@Entity()
class Book {
  @PrimaryKey()
  id!: number;

  @Property()
  title!: string;
}

Drizzle ORM:

const books = pgTable('books', {
  id: serial('id').primaryKey(),
  title: text('title').notNull(),
});

MikroORM uses decorators and classes for entity definitions, while Drizzle ORM employs a more functional approach with table and column definitions. MikroORM's syntax is more verbose but offers more built-in features, whereas Drizzle ORM's syntax is more concise and straightforward for simple schema definitions.

A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js

Pros of Bookshelf

  • Mature and well-established ORM with a large community and extensive documentation
  • Supports complex relationships and eager loading out of the box
  • Provides a flexible plugin system for extending functionality

Cons of Bookshelf

  • Heavier and more complex API compared to Drizzle ORM's lightweight approach
  • Less TypeScript-friendly, with limited type inference capabilities
  • Slower development and fewer recent updates compared to Drizzle ORM

Code Comparison

Bookshelf:

const User = bookshelf.Model.extend({
  tableName: 'users',
  posts: function() {
    return this.hasMany(Post);
  }
});

Drizzle ORM:

const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name'),
});

const posts = pgTable('posts', {
  id: serial('id').primaryKey(),
  userId: integer('user_id').references(() => users.id),
});

Bookshelf offers a more traditional OOP approach with model definitions, while Drizzle ORM provides a more declarative, TypeScript-first syntax for defining schemas and relationships. Drizzle ORM's approach results in better type inference and a more lightweight API, but Bookshelf's maturity and extensive features may be preferred for complex applications with intricate data relationships.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README


Headless ORM for NodeJS, TypeScript and JavaScript 🚀

Website • Documentation • Twitter • Discord


What's Drizzle?

Drizzle is a modern TypeScript ORM developers wanna use in their next project. It is lightweight at only ~7.4kb minified+gzipped, and it's tree shakeable with exactly 0 dependencies.

Drizzle supports every PostgreSQL, MySQL and SQLite database, including serverless ones like Turso, Neon, Xata, PlanetScale, Cloudflare D1, FlyIO LiteFS, Vercel Postgres, Supabase and AWS Data API. No bells and whistles, no Rust binaries, no serverless adapters, everything just works out of the box.

Drizzle is serverless-ready by design. It works in every major JavaScript runtime like NodeJS, Bun, Deno, Cloudflare Workers, Supabase functions, any Edge runtime, and even in browsers.
With Drizzle you can be fast out of the box and save time and costs while never introducing any data proxies into your infrastructure.

While you can use Drizzle as a JavaScript library, it shines with TypeScript. It lets you declare SQL schemas and build both relational and SQL-like queries, while keeping the balance between type-safety and extensibility for toolmakers to build on top.

Ecosystem

While Drizzle ORM remains a thin typed layer on top of SQL, we made a set of tools for people to have best possible developer experience.

Drizzle comes with a powerful Drizzle Kit CLI companion for you to have hassle-free migrations. It can generate SQL migration files for you or apply schema changes directly to the database.

We also have Drizzle Studio for you to effortlessly browse and manipulate data in your database of choice.

Documentation

Check out the full documentation on the website.

Our sponsors ❤️

NPM DownloadsLast 30 Days