Skip to content

Commit d064e0a

Browse files
committed
Merge branch 'main' of github.com:drizzle-team/drizzle-orm-docs
2 parents 604de40 + 407829c commit d064e0a

18 files changed

+508
-225
lines changed

src/components/markdown/get-started/QueryDatabase.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ Let's **update** the `src/index.ts` file with queries to create, read, update, a
55
<CodeWithProps dialect={props.dialect} env_variable={props.env_variable}>
66
```typescript copy filename="src/index.ts"
77
import 'dotenv/config';
8-
import { drizzle, eq } from 'drizzle-orm';
8+
import { drizzle } from 'drizzle-orm/$dialect$';
9+
import { eq } from 'drizzle-orm';
910
import { usersTable } from './db/schema';
11+
12+
const db = drizzle(process.env.$env_variable$!);
1013

1114
async function main() {
12-
const db = await drizzle("$dialect$", process.env.$env_variable$!);
13-
1415
const user: typeof usersTable.$inferInsert = {
1516
name: 'John',
1617
age: 30,

src/components/markdown/get-started/QueryDatabaseUpdated.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import CodeWithProps from "@/components/markdown/CodeWithProps.astro";
33
<CodeWithProps dialect={props.dialect} env_variable={props.env_variable}>
44
```typescript copy filename="src/index.ts"
55
import 'dotenv/config';
6-
import { drizzle, eq } from 'drizzle-orm';
6+
import { drizzle } from 'drizzle-orm/$dialect$';
7+
import { eq } from 'drizzle-orm';
78
import { usersTable } from './db/schema';
89

9-
async function main() {
10-
const db = await drizzle("$dialect$", process.env.$env_variable$!);
10+
const db = drizzle(process.env.$env_variable$!);
1111

12+
async function main() {
1213
const user: typeof usersTable.$inferInsert = {
1314
name: 'John',
1415
age: 30,

src/components/markdown/get-started/mysql/ConnectMySQL.mdx

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,45 @@ import CodeTabs from "@mdx/CodeTabs.astro";
33

44
Create a `index.ts` file in the `src/db` directory and initialize the connection:
55

6-
<CodeTabs items={['mysql2', 'mysql2 with config']}>
6+
<CodeTabs items={['mysql2', 'mysql2 with config', 'your mysql2 driver']}>
77
```typescript copy
88
import 'dotenv/config';
9-
import { drizzle } from "drizzle-orm/connect";
9+
import { drizzle } from "drizzle-orm/mysql2";
1010

11-
async function main() {
12-
const db = await drizzle("mysql2", process.env.DATABASE_URL);
13-
}
14-
15-
main();
11+
const db = drizzle(process.env.DATABASE_URL);
1612
```
1713
```typescript copy
1814
import 'dotenv/config';
19-
import { drizzle } from "drizzle-orm/connect";
15+
import { drizzle } from "drizzle-orm/mysql2";
2016

17+
// You can specify any property from the mysql2 connection options
18+
const db = drizzle({ connection: { uri: process.env.DATABASE_URL }});
19+
```
20+
```ts
21+
import 'dotenv/config';
22+
import { drizzle } from "drizzle-orm/mysql2";
23+
import mysql from "mysql2/promise";
24+
25+
const poolConnection = mysql.createPool({
26+
host: "host",
27+
user: "user",
28+
database: "database",
29+
});
30+
const db = drizzle({ client: poolConnection });
31+
32+
// or if you need client connection
2133
async function main() {
22-
// You can specify any property from the mysql2 connection options
23-
const db = await drizzle("mysql2", { connection:{ uri: process.env.DATABASE_URL }});
34+
const connection = await mysql.createConnection({
35+
host: "host",
36+
user: "user",
37+
database: "database",
38+
});
39+
const db = drizzle({ client: connection });
2440
}
25-
2641
main();
2742
```
2843
</CodeTabs>
2944

30-
If you need a synchronous connection, you can use our additional connection API, where you specify a driver connection and pass it to the Drizzle instance.
31-
There're two ways you can connect to the MySQL with `mysql2` driver, either single `client` connection or a `pool`.
32-
33-
<CodeTabs items={['Client connection', 'Pool connection']}>
34-
```typescript copy
35-
import 'dotenv/config';
36-
import { drizzle } from "drizzle-orm/mysql2";
37-
import mysql from "mysql2/promise";
38-
39-
async function main() {
40-
const connection = await mysql.createConnection({
41-
host: "host",
42-
user: "user",
43-
database: "database",
44-
});
45-
46-
const db = drizzle(connection);
47-
}
48-
49-
main();
50-
```
51-
```typescript copy
52-
import 'dotenv/config';
53-
import { drizzle } from "drizzle-orm/mysql2";
54-
import mysql from "mysql2/promise";
55-
async function main() {
56-
const poolConnection = mysql.createPool({
57-
host: "host",
58-
user: "user",
59-
database: "database",
60-
});
61-
62-
const db = drizzle(poolConnection);
63-
}
64-
65-
main();
66-
```
67-
</CodeTabs>
68-
6945
<Callout type="warning" emoji="⚙️">
7046
For the built in `migrate` function with DDL migrations we and drivers strongly encourage you to use single `client` connection.
7147

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
11
Create a `index.ts` file in the `src/db` directory and initialize the connection:
22

3-
```typescript copy"
4-
import { drizzle } from "drizzle-orm/connect";
5-
6-
async function main() {
7-
const db = await drizzle('planetscale', { connection: {
8-
host: process.env.DATABASE_HOST!,
9-
username: process.env.DATABASE_USERNAME!,
10-
password: process.env.DATABASE_PASSWORD!,
11-
}});
12-
}
3+
```typescript copy
4+
import { drizzle } from "drizzle-orm/planetscale-serverless";
135

14-
main();
6+
const db = await drizzle({ connection: {
7+
host: process.env.DATABASE_HOST!,
8+
username: process.env.DATABASE_USERNAME!,
9+
password: process.env.DATABASE_PASSWORD!,
10+
}});
1511
```
1612

17-
If you need a synchronous connection, you can use our additional connection API,
18-
where you specify a driver connection and pass it to the Drizzle instance.
19-
13+
If you need to provide your existing driver
2014
```typescript copy"
2115
import { drizzle } from "drizzle-orm/planetscale-serverless";
2216
import { Client } from "@planetscale/database";
2317

24-
async function main() {
25-
const client = new Client({
26-
host: process.env.DATABASE_HOST!,
27-
username: process.env.DATABASE_USERNAME!,
28-
password: process.env.DATABASE_PASSWORD!,
29-
});
30-
31-
const db = drizzle(client);
32-
}
18+
const client = new Client({
19+
host: process.env.DATABASE_HOST!,
20+
username: process.env.DATABASE_USERNAME!,
21+
password: process.env.DATABASE_PASSWORD!,
22+
});
3323

34-
main();
24+
const db = drizzle({ client: client });
3525
```
Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
Create a `index.ts` file in the `src/db` directory and initialize the connection:
22

3-
```typescript copy filename="index.ts"
4-
import { drizzle } from 'drizzle-orm/connect';
5-
6-
async function main() {
7-
const db = await drizzle('tidb-serverless', process.env.DATABASE_URL!);
8-
}
3+
```typescript copy
4+
import { drizzle } from 'drizzle-orm/tidb-serverless';
95

10-
main();
6+
const db = drizzle(process.env.DATABASE_URL!);
117
```
128

13-
If you need a synchronous connection, you can use our additional connection API,
14-
where you specify a driver connection and pass it to the Drizzle instance.
15-
16-
```typescript copy"
9+
If you need to provide your existing driver:
10+
```typescript copy
1711
import { connect } from '@tidbcloud/serverless';
1812
import { drizzle } from 'drizzle-orm/tidb-serverless';
1913

20-
async function main() {
21-
const client = connect({ url: process.env.DATABASE_URL! });
22-
const db = drizzle(client);
23-
}
24-
25-
main();
14+
const client = connect({ url: process.env.DATABASE_URL! });
15+
const db = drizzle({ client: client });
2616
```

src/components/markdown/get-started/mysql/QueryPlanetScale.mdx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import CodeWithProps from "@/components/markdown/CodeWithProps.astro";
22

33
Let's **update** the `src/index.ts` file with queries to create, read, update, and delete users
44

5-
<CodeWithProps dialect={props.dialect} env_variable={props.env_variable}>
65
```typescript copy filename="src/index.ts"
76
import 'dotenv/config';
8-
import { drizzle, eq } from 'drizzle-orm';
7+
import { eq } from 'drizzle-orm';
8+
import { drizzle } from 'drizzle-orm/planetscale-serverless';
99
import { usersTable } from './db/schema';
1010

11-
async function main() {
12-
const db = await drizzle('planetscale', { connection: {
13-
host: process.env.DATABASE_HOST!,
14-
username: process.env.DATABASE_USERNAME!,
15-
password: process.env.DATABASE_PASSWORD!,
16-
}});
11+
const db = drizzle({ connection: {
12+
host: process.env.DATABASE_HOST!,
13+
username: process.env.DATABASE_USERNAME!,
14+
password: process.env.DATABASE_PASSWORD!,
15+
}});
1716

17+
async function main() {
1818
const user: typeof usersTable.$inferInsert = {
1919
name: 'John',
2020
age: 30,
@@ -48,5 +48,4 @@ async function main() {
4848
}
4949

5050
main();
51-
```
52-
</CodeWithProps>
51+
```

src/components/markdown/get-started/postgresql/ConnectNeon.mdx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,18 @@ import Section from "@mdx/Section.astro";
55
Create a `index.ts` file in the `src/db` directory and initialize the connection:
66

77
```typescript
8-
import { drizzle } from 'drizzle-orm/connect';
9-
10-
async function main() {
11-
const db = await drizzle("neon-http", process.env.DATABASE_URL);
12-
}
8+
import { drizzle } from 'drizzle-orm/neon-http';
139

14-
main();
10+
const db = await drizzle("neon-http", process.env.DATABASE_URL);
1511
```
1612

1713
If you need a synchronous connection, you can use our additional connection API,
1814
where you specify a driver connection and pass it to the Drizzle instance.
1915

2016
```typescript
2117
import { neon } from '@neondatabase/serverless';
22-
import { drizzle } from 'drizzle-orm/neon-http';
23-
24-
async function main() {
25-
const sql = neon(process.env.DATABASE_URL!);
26-
const db = drizzle(sql);
27-
}
18+
import { drizzle } from 'drizzle-orm/neon-serverless';
2819

29-
main();
20+
const sql = neon(process.env.DATABASE_URL!);
21+
const db = drizzle(sql);
3022
```

src/components/markdown/get-started/postgresql/ConnectPostgreSQL.mdx

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,34 @@ import CodeTabs from "@mdx/CodeTabs.astro";
22

33
Create a `index.ts` file in the `src/db` directory and initialize the connection:
44

5-
<CodeTabs items={["node-postgres", "node-postgres with config"]}>
5+
<CodeTabs items={["node-postgres", "node-postgres with config", "your node-postgres driver"]}>
66
```typescript copy
77
import 'dotenv/config';
8-
import { drizzle } from 'drizzle-orm/connect';
8+
import { drizzle } from 'drizzle-orm/node-postgres';
99

10-
async function main() {
11-
const db = await drizzle("node-postgres", process.env.DATABASE_URL!);
12-
}
13-
14-
main();
10+
const db = drizzle(process.env.DATABASE_URL!);
1511
```
1612
```typescript copy
1713
import 'dotenv/config';
18-
import { drizzle } from 'drizzle-orm/connect';
19-
20-
async function main() {
21-
// You can specify any property from the node-postgres connection options
22-
const db = await drizzle("node-postgres", {
23-
connection: {
24-
connectionString: process.env.DATABASE_URL!,
25-
ssl: true
26-
}
27-
});
28-
}
29-
30-
main();
14+
import { drizzle } from 'drizzle-orm/node-postgres';
15+
16+
// You can specify any property from the node-postgres connection options
17+
const db = await drizzle("node-postgres", {
18+
connection: {
19+
connectionString: process.env.DATABASE_URL!,
20+
ssl: true
21+
}
22+
});
3123
```
32-
</CodeTabs>
33-
34-
If you need a synchronous connection, you can use our additional connection API,
35-
where you specify a driver connection and pass it to the Drizzle instance.
36-
3724
```typescript copy
3825
import 'dotenv/config';
3926
import { pgTable, serial, text, varchar } from "drizzle-orm/pg-core";
4027
import { drizzle } from "drizzle-orm/node-postgres";
4128
import { Pool } from "pg";
4229

43-
async function main() {
44-
const pool = new Pool({
45-
connectionString: process.env.DATABASE_URL!,
46-
});
47-
const db = drizzle(pool);
48-
}
49-
50-
main();
51-
```
30+
const pool = new Pool({
31+
connectionString: process.env.DATABASE_URL!,
32+
});
33+
const db = drizzle(pool);
34+
```
35+
</CodeTabs>

0 commit comments

Comments
 (0)