
Research
/Security News
Laravel Lang Compromised with RCE Backdoor Across 700+ Versions
Laravel Lang packages were compromised with an RCE backdoor across hundreds of versions, exposing cloud, CI/CD, and developer secrets.
drizzle-orm
Advanced tools
Drizzle ORM is a TypeScript ORM for SQL databases designed with maximum type safety in mind. It comes with a drizzle-kit CLI companion for automatic SQL migrations generation. Drizzle ORM is meant to be a library, not a framework. It stays as an opt-in solution all the time at any levels. The ORM's main philosophy is "If you know SQL, you know Drizzle ORM". We follow the SQL-like syntax whenever possible, are strongly typed ground up, and fail at compile time, not in runtime.
Drizzle ORM is being battle-tested on production projects by multiple teams π Give it a try and let us know if you have any questions or feedback on Discord.
Check the full documentation on the website
| Database | Support | ||
|---|---|---|---|
| PostgreSQL | β | Docs | |
| MySQL | β | Docs | |
| SQLite | β | Docs | |
| Cloudflare D1 | β | Docs | Website |
| libSQL | β | Docs | Website |
| Turso | β | Docs | Website |
| PlanetScale | β | Docs | Website |
| Neon | β | Docs | Website |
| Vercel Postgres | β | Docs | Website |
| Supabase | β | Docs | Website |
| DynamoDB | β³ | ||
| MS SQL | β³ | ||
| CockroachDB | β³ |
npm install drizzle-orm
npm install -D drizzle-kit
Note: don't forget to install
pgand@types/pgpackages for this example to work.
import { drizzle } from 'drizzle-orm/node-postgres';
import { integer, pgTable, serial, text, timestamp, varchar } from 'drizzle-orm/pg-core';
import { InferModel, eq, sql } from 'drizzle-orm';
import { Pool } from 'pg';
export const users = pgTable('users', {
id: serial('id').primaryKey(),
fullName: text('full_name').notNull(),
phone: varchar('phone', { length: 20 }).notNull(),
role: text('role', { enum: ['user', 'admin'] }).default('user').notNull(),
cityId: integer('city_id').references(() => cities.id),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
export type User = InferModel<typeof users>;
export type NewUser = InferModel<typeof users, 'insert'>;
export const cities = pgTable('cities', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
});
export type City = InferModel<typeof cities>;
export type NewCity = InferModel<typeof cities, 'insert'>;
const pool = new Pool({
connectionString: 'postgres://user:password@host:port/db',
});
const db = drizzle(pool);
// Insert
const newUser: NewUser = {
fullName: 'John Doe',
phone: '+123456789',
};
const insertedUsers /* : User[] */ = await db.insert(users).values(newUser).returning();
const insertedUser = insertedUsers[0]!;
const newCity: NewCity = {
name: 'New York',
};
const insertedCities /* : City[] */ = await db.insert(cities).values(newCity).returning();
const insertedCity = insertedCities[0]!;
// Update
const updateResult /* : { updated: Date }[] */ = await db.update(users)
.set({ cityId: insertedCity.id, updatedAt: new Date() })
.where(eq(users.id, insertedUser.id))
.returning({ updated: users.updatedAt });
// Select
const allUsers /* : User[] */ = await db.select().from(users);
// Select custom fields
const upperCaseNames /* : { id: number; name: string }[] */ = await db
.select({
id: users.id,
name: sql<string>`upper(${users.fullName})`,
})
.from(users);
// Joins
// You wouldn't BELIEVE how SMART the result type is! π±
const allUsersWithCities = await db
.select({
id: users.id,
name: users.fullName,
city: {
id: cities.id,
name: cities.name,
},
})
.from(users)
.leftJoin(cities, eq(users.cityId, cities.id));
// Delete
const deletedNames /* : { name: string }[] */ = await db.delete(users)
.where(eq(users.id, insertedUser.id))
.returning({ name: users.fullName });
See full docs for further reference:
Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite, and Microsoft SQL Server. It features solid transaction support, relations, eager and lazy loading, read replication, and more. Compared to Drizzle ORM, Sequelize has a larger community and more extensive documentation but may lack some of the type safety features that Drizzle ORM offers.
TypeORM is an ORM for TypeScript and JavaScript (ES7, ES6, ES5). It supports many database systems including MySQL, MariaDB, PostgreSQL, SQLite, and more. TypeORM is known for its extensive feature set and active community. It provides decorators for defining entities and supports advanced features like migrations, caching, and more. Compared to Drizzle ORM, TypeORM offers more features but may be more complex to set up and use.
Knex.js is a SQL query builder for PostgreSQL, MySQL, MariaDB, SQLite3, and Oracle. It features a flexible and powerful API for building SQL queries and managing database schema. While Knex.js is not a full-fledged ORM, it can be used in conjunction with other libraries to provide ORM-like functionality. Compared to Drizzle ORM, Knex.js offers more control over raw SQL queries but lacks the built-in type safety and higher-level abstractions.
FAQs
Drizzle ORM package for SQL databases
The npm package drizzle-orm receives a total of 9,015,984 weekly downloads. As such, drizzle-orm popularity was classified as popular.
We found that drizzle-orm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 4 open source maintainers collaborating on the project.
Did you know?

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.

Research
/Security News
Laravel Lang packages were compromised with an RCE backdoor across hundreds of versions, exposing cloud, CI/CD, and developer secrets.

Security News
Socket found a malicious postinstall hook across 700+ GitHub repos, including PHP packages on Packagist and Node.js project repositories.

Security News
Vibe coding at scale is reshaping how packages are created, contributed, and selected across the software supply chain