drizzle-orm 0.29.2-76177ff → 0.29.2-aa669c4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -145
- package/package.json +49 -49
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/README.md
CHANGED
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
</div>
|
|
5
5
|
|
|
6
6
|
<br/>
|
|
7
|
-
|
|
8
|
-
|
|
9
7
|
<div align="center">
|
|
10
8
|
<h3>Headless ORM for NodeJS, TypeScript and JavaScript 🚀</h3>
|
|
11
9
|
<a href="https://orm.drizzle.team">Website</a> •
|
|
@@ -16,158 +14,31 @@
|
|
|
16
14
|
|
|
17
15
|
<br/>
|
|
18
16
|
<br/>
|
|
19
|
-
<div>
|
|
20
|
-
<img alt="npm" src="https://img.shields.io/npm/dm/drizzle-orm">
|
|
21
|
-
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/min/drizzle-orm">
|
|
22
|
-
<img alt="License" src="https://img.shields.io/npm/l/drizzle-orm">
|
|
23
|
-
</div>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
Drizzle ORM is a TypeScript ORM for SQL databases designed with maximum type safety in mind. It comes with a [drizzle-kit](https://github.com/drizzle-team/drizzle-kit-mirror) 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.
|
|
29
|
-
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.
|
|
30
17
|
|
|
31
|
-
|
|
18
|
+
### What's Drizzle?
|
|
19
|
+
Drizzle is a modern TypeScript ORM developers [wanna use in their next project](https://stateofdb.com/tools/drizzle).
|
|
20
|
+
It is [lightweight](https://bundlephobia.com/package/drizzle-orm) at only ~7.4kb minified+gzipped, it's tree shakeable with exactly 0 dependencies.
|
|
32
21
|
|
|
33
|
-
|
|
22
|
+
**Drizzle supports every PostgreSQL, MySQL and SQLite databases**, including serverless ones like [Turso](https://orm.drizzle.team/docs/get-started-sqlite#turso), [Neon](https://orm.drizzle.team/docs/get-started-postgresql#neon), [Xata](xata.io), [PlanetScale](https://orm.drizzle.team/docs/get-started-mysql#planetscale), [Cloudflare D1](https://orm.drizzle.team/docs/get-started-sqlite#cloudflare-d1), [FlyIO LiteFS](https://fly.io/docs/litefs/), [Vercel Postgres](https://orm.drizzle.team/docs/get-started-postgresql#vercel-postgres), [Supabase](https://orm.drizzle.team/docs/get-started-postgresql#supabase) and [AWS Data API](https://orm.drizzle.team/docs/get-started-postgresql#aws-data-api). No bells and whistles, no rust binaries, no serverless adapters, everything just works out of the box.
|
|
34
23
|
|
|
35
|
-
-
|
|
36
|
-
|
|
37
|
-
- No ORM learning curve
|
|
38
|
-
- SQL-like syntax for table definitions and queries
|
|
39
|
-
- Best in class fully typed joins
|
|
40
|
-
- Fully typed partial and non-partial selects of any complexity
|
|
41
|
-
- Auto-inferring of TS types for DB models for selections and insertions separately
|
|
42
|
-
- [Zod schema generation](/drizzle-zod/README.md)
|
|
43
|
-
- Zero dependencies
|
|
24
|
+
**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.
|
|
25
|
+
With Drizzle you can be [**fast out of the box**](https://orm.drizzle.team/benchmarks), save time and costs while never introducing any data proxies into your infrastructure.
|
|
44
26
|
|
|
45
|
-
|
|
27
|
+
While you can use Drizzle as a JavaScript library, it shines in the TypeScript. It lets you [**declare SQL schema**](https://orm.drizzle.team/docs/sql-schema-declaration) and build both [**relational**](https://orm.drizzle.team/docs/rqb) and [**SQL-like queries**](https://orm.drizzle.team/docs/select), while keeping the balance between type-safety and extensibility for toolmakers to build on top.
|
|
46
28
|
|
|
47
|
-
|
|
29
|
+
### Ecosystem
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
Drizzle comes with a powerful [**Drizzle Kit**](https://orm.drizzle.team/kit-docs/overview) CLI companion for you to have hasstle-free migrations. It can generate SQL migration files for you or apply schema changes directly to the database.
|
|
33
|
+
|
|
34
|
+
And we have a [**Drizzle Studio**](https://orm.drizzle.team/drizzle-studio/overview) for you to effortlessly browse and manipulate data in your database of choice.
|
|
48
35
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
| :-------------- | :-----: | :------------------------------------------------ | :-------------------------------------------------------------------- |
|
|
52
|
-
| PostgreSQL | ✅ | [Docs](https://orm.drizzle.team/docs/quick-start) | |
|
|
53
|
-
| MySQL | ✅ | [Docs](https://orm.drizzle.team/docs/quick-start) | |
|
|
54
|
-
| SQLite | ✅ | [Docs](https://orm.drizzle.team/docs/quick-start) | |
|
|
55
|
-
| Cloudflare D1 | ✅ | [Docs](https://driz.link/docs-d1) | [Website](https://developers.cloudflare.com/d1) |
|
|
56
|
-
| libSQL | ✅ | [Docs](/examples/libsql/README.md) | [Website](https://libsql.org) |
|
|
57
|
-
| Turso | ✅ | [Docs](https://driz.link/docs-turso) | [Website](https://turso.tech) |
|
|
58
|
-
| PlanetScale | ✅ | [Docs](https://driz.link/docs-planetscale) | [Website](https://planetscale.com/) |
|
|
59
|
-
| Neon | ✅ | [Docs](https://driz.link/docs-neon) | [Website](https://neon.tech/) |
|
|
60
|
-
| Vercel Postgres | ✅ | [Docs](https://driz.link/docs-vercel-postgres) | [Website](https://vercel.com/docs/storage/vercel-postgres/quickstart) |
|
|
61
|
-
| Supabase | ✅ | [Docs](https://driz.link/docs-supabase) | [Website](https://supabase.com) |
|
|
62
|
-
| DynamoDB | ⏳ | | |
|
|
63
|
-
| MS SQL | ⏳ | | |
|
|
64
|
-
| CockroachDB | ⏳ | | |
|
|
65
|
-
|
|
66
|
-
## Our sponsors ❤️
|
|
36
|
+
### Documentation
|
|
37
|
+
Check out the full documentation on [the website](https://orm.drizzle.team/docs/overview)
|
|
67
38
|
|
|
39
|
+
### Our sponsors ❤️
|
|
68
40
|
<p align="center">
|
|
69
41
|
<a href="https://drizzle.team" target="_blank">
|
|
70
42
|
<img src='https://api.drizzle.team/github/sponsors/svg'/>
|
|
71
43
|
</a>
|
|
72
44
|
</p>
|
|
73
|
-
|
|
74
|
-
## Installation
|
|
75
|
-
|
|
76
|
-
```bash
|
|
77
|
-
npm install drizzle-orm
|
|
78
|
-
npm install -D drizzle-kit
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## Feature showcase (PostgreSQL)
|
|
82
|
-
|
|
83
|
-
> **Note**: don't forget to install `pg` and `@types/pg` packages for this example to work.
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
87
|
-
import { integer, pgTable, serial, text, timestamp, varchar } from 'drizzle-orm/pg-core';
|
|
88
|
-
import { InferModel, eq, sql } from 'drizzle-orm';
|
|
89
|
-
import { Pool } from 'pg';
|
|
90
|
-
|
|
91
|
-
export const users = pgTable('users', {
|
|
92
|
-
id: serial('id').primaryKey(),
|
|
93
|
-
fullName: text('full_name').notNull(),
|
|
94
|
-
phone: varchar('phone', { length: 20 }).notNull(),
|
|
95
|
-
role: text('role', { enum: ['user', 'admin'] }).default('user').notNull(),
|
|
96
|
-
cityId: integer('city_id').references(() => cities.id),
|
|
97
|
-
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
98
|
-
updatedAt: timestamp('updated_at').defaultNow().notNull(),
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
export type User = InferModel<typeof users>;
|
|
102
|
-
export type NewUser = InferModel<typeof users, 'insert'>;
|
|
103
|
-
|
|
104
|
-
export const cities = pgTable('cities', {
|
|
105
|
-
id: serial('id').primaryKey(),
|
|
106
|
-
name: text('name').notNull(),
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
export type City = InferModel<typeof cities>;
|
|
110
|
-
export type NewCity = InferModel<typeof cities, 'insert'>;
|
|
111
|
-
|
|
112
|
-
const pool = new Pool({
|
|
113
|
-
connectionString: 'postgres://user:password@host:port/db',
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const db = drizzle(pool);
|
|
117
|
-
|
|
118
|
-
// Insert
|
|
119
|
-
const newUser: NewUser = {
|
|
120
|
-
fullName: 'John Doe',
|
|
121
|
-
phone: '+123456789',
|
|
122
|
-
};
|
|
123
|
-
const insertedUsers /* : User[] */ = await db.insert(users).values(newUser).returning();
|
|
124
|
-
const insertedUser = insertedUsers[0]!;
|
|
125
|
-
|
|
126
|
-
const newCity: NewCity = {
|
|
127
|
-
name: 'New York',
|
|
128
|
-
};
|
|
129
|
-
const insertedCities /* : City[] */ = await db.insert(cities).values(newCity).returning();
|
|
130
|
-
const insertedCity = insertedCities[0]!;
|
|
131
|
-
|
|
132
|
-
// Update
|
|
133
|
-
const updateResult /* : { updated: Date }[] */ = await db.update(users)
|
|
134
|
-
.set({ cityId: insertedCity.id, updatedAt: new Date() })
|
|
135
|
-
.where(eq(users.id, insertedUser.id))
|
|
136
|
-
.returning({ updated: users.updatedAt });
|
|
137
|
-
|
|
138
|
-
// Select
|
|
139
|
-
const allUsers /* : User[] */ = await db.select().from(users);
|
|
140
|
-
|
|
141
|
-
// Select custom fields
|
|
142
|
-
const upperCaseNames /* : { id: number; name: string }[] */ = await db
|
|
143
|
-
.select({
|
|
144
|
-
id: users.id,
|
|
145
|
-
name: sql<string>`upper(${users.fullName})`,
|
|
146
|
-
})
|
|
147
|
-
.from(users);
|
|
148
|
-
|
|
149
|
-
// Joins
|
|
150
|
-
// You wouldn't BELIEVE how SMART the result type is! 😱
|
|
151
|
-
const allUsersWithCities = await db
|
|
152
|
-
.select({
|
|
153
|
-
id: users.id,
|
|
154
|
-
name: users.fullName,
|
|
155
|
-
city: {
|
|
156
|
-
id: cities.id,
|
|
157
|
-
name: cities.name,
|
|
158
|
-
},
|
|
159
|
-
})
|
|
160
|
-
.from(users)
|
|
161
|
-
.leftJoin(cities, eq(users.cityId, cities.id));
|
|
162
|
-
|
|
163
|
-
// Delete
|
|
164
|
-
const deletedNames /* : { name: string }[] */ = await db.delete(users)
|
|
165
|
-
.where(eq(users.id, insertedUser.id))
|
|
166
|
-
.returning({ name: users.fullName });
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
**See full docs for further reference:**
|
|
170
|
-
|
|
171
|
-
- [PostgreSQL](./drizzle-orm/src/pg-core/README.md)
|
|
172
|
-
- [MySQL](./drizzle-orm/src/mysql-core/README.md)
|
|
173
|
-
- [SQLite](./drizzle-orm/src/sqlite-core/README.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-orm",
|
|
3
|
-
"version": "0.29.2-
|
|
3
|
+
"version": "0.29.2-aa669c4",
|
|
4
4
|
"description": "Drizzle ORM package for SQL databases",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -1431,54 +1431,6 @@
|
|
|
1431
1431
|
"types": "./pg-proxy/session.d.ts",
|
|
1432
1432
|
"default": "./pg-proxy/session.js"
|
|
1433
1433
|
},
|
|
1434
|
-
"./planetscale-serverless/driver": {
|
|
1435
|
-
"import": {
|
|
1436
|
-
"types": "./planetscale-serverless/driver.d.ts",
|
|
1437
|
-
"default": "./planetscale-serverless/driver.js"
|
|
1438
|
-
},
|
|
1439
|
-
"require": {
|
|
1440
|
-
"types": "./planetscale-serverless/driver.d.cts",
|
|
1441
|
-
"default": "./planetscale-serverless/driver.cjs"
|
|
1442
|
-
},
|
|
1443
|
-
"types": "./planetscale-serverless/driver.d.ts",
|
|
1444
|
-
"default": "./planetscale-serverless/driver.js"
|
|
1445
|
-
},
|
|
1446
|
-
"./planetscale-serverless": {
|
|
1447
|
-
"import": {
|
|
1448
|
-
"types": "./planetscale-serverless/index.d.ts",
|
|
1449
|
-
"default": "./planetscale-serverless/index.js"
|
|
1450
|
-
},
|
|
1451
|
-
"require": {
|
|
1452
|
-
"types": "./planetscale-serverless/index.d.cts",
|
|
1453
|
-
"default": "./planetscale-serverless/index.cjs"
|
|
1454
|
-
},
|
|
1455
|
-
"types": "./planetscale-serverless/index.d.ts",
|
|
1456
|
-
"default": "./planetscale-serverless/index.js"
|
|
1457
|
-
},
|
|
1458
|
-
"./planetscale-serverless/migrator": {
|
|
1459
|
-
"import": {
|
|
1460
|
-
"types": "./planetscale-serverless/migrator.d.ts",
|
|
1461
|
-
"default": "./planetscale-serverless/migrator.js"
|
|
1462
|
-
},
|
|
1463
|
-
"require": {
|
|
1464
|
-
"types": "./planetscale-serverless/migrator.d.cts",
|
|
1465
|
-
"default": "./planetscale-serverless/migrator.cjs"
|
|
1466
|
-
},
|
|
1467
|
-
"types": "./planetscale-serverless/migrator.d.ts",
|
|
1468
|
-
"default": "./planetscale-serverless/migrator.js"
|
|
1469
|
-
},
|
|
1470
|
-
"./planetscale-serverless/session": {
|
|
1471
|
-
"import": {
|
|
1472
|
-
"types": "./planetscale-serverless/session.d.ts",
|
|
1473
|
-
"default": "./planetscale-serverless/session.js"
|
|
1474
|
-
},
|
|
1475
|
-
"require": {
|
|
1476
|
-
"types": "./planetscale-serverless/session.d.cts",
|
|
1477
|
-
"default": "./planetscale-serverless/session.cjs"
|
|
1478
|
-
},
|
|
1479
|
-
"types": "./planetscale-serverless/session.d.ts",
|
|
1480
|
-
"default": "./planetscale-serverless/session.js"
|
|
1481
|
-
},
|
|
1482
1434
|
"./postgres-js/driver": {
|
|
1483
1435
|
"import": {
|
|
1484
1436
|
"types": "./postgres-js/driver.d.ts",
|
|
@@ -1527,6 +1479,54 @@
|
|
|
1527
1479
|
"types": "./postgres-js/session.d.ts",
|
|
1528
1480
|
"default": "./postgres-js/session.js"
|
|
1529
1481
|
},
|
|
1482
|
+
"./planetscale-serverless/driver": {
|
|
1483
|
+
"import": {
|
|
1484
|
+
"types": "./planetscale-serverless/driver.d.ts",
|
|
1485
|
+
"default": "./planetscale-serverless/driver.js"
|
|
1486
|
+
},
|
|
1487
|
+
"require": {
|
|
1488
|
+
"types": "./planetscale-serverless/driver.d.cts",
|
|
1489
|
+
"default": "./planetscale-serverless/driver.cjs"
|
|
1490
|
+
},
|
|
1491
|
+
"types": "./planetscale-serverless/driver.d.ts",
|
|
1492
|
+
"default": "./planetscale-serverless/driver.js"
|
|
1493
|
+
},
|
|
1494
|
+
"./planetscale-serverless": {
|
|
1495
|
+
"import": {
|
|
1496
|
+
"types": "./planetscale-serverless/index.d.ts",
|
|
1497
|
+
"default": "./planetscale-serverless/index.js"
|
|
1498
|
+
},
|
|
1499
|
+
"require": {
|
|
1500
|
+
"types": "./planetscale-serverless/index.d.cts",
|
|
1501
|
+
"default": "./planetscale-serverless/index.cjs"
|
|
1502
|
+
},
|
|
1503
|
+
"types": "./planetscale-serverless/index.d.ts",
|
|
1504
|
+
"default": "./planetscale-serverless/index.js"
|
|
1505
|
+
},
|
|
1506
|
+
"./planetscale-serverless/migrator": {
|
|
1507
|
+
"import": {
|
|
1508
|
+
"types": "./planetscale-serverless/migrator.d.ts",
|
|
1509
|
+
"default": "./planetscale-serverless/migrator.js"
|
|
1510
|
+
},
|
|
1511
|
+
"require": {
|
|
1512
|
+
"types": "./planetscale-serverless/migrator.d.cts",
|
|
1513
|
+
"default": "./planetscale-serverless/migrator.cjs"
|
|
1514
|
+
},
|
|
1515
|
+
"types": "./planetscale-serverless/migrator.d.ts",
|
|
1516
|
+
"default": "./planetscale-serverless/migrator.js"
|
|
1517
|
+
},
|
|
1518
|
+
"./planetscale-serverless/session": {
|
|
1519
|
+
"import": {
|
|
1520
|
+
"types": "./planetscale-serverless/session.d.ts",
|
|
1521
|
+
"default": "./planetscale-serverless/session.js"
|
|
1522
|
+
},
|
|
1523
|
+
"require": {
|
|
1524
|
+
"types": "./planetscale-serverless/session.d.cts",
|
|
1525
|
+
"default": "./planetscale-serverless/session.cjs"
|
|
1526
|
+
},
|
|
1527
|
+
"types": "./planetscale-serverless/session.d.ts",
|
|
1528
|
+
"default": "./planetscale-serverless/session.js"
|
|
1529
|
+
},
|
|
1530
1530
|
"./query-builders/query-builder": {
|
|
1531
1531
|
"import": {
|
|
1532
1532
|
"types": "./query-builders/query-builder.d.ts",
|
package/version.cjs
CHANGED
package/version.d.cts
CHANGED
package/version.d.ts
CHANGED
package/version.js
CHANGED