Skip to content

Commit 88964a9

Browse files
committed
Added bun sql get started
1 parent 36b56a1 commit 88964a9

File tree

8 files changed

+204
-5
lines changed

8 files changed

+204
-5
lines changed

src/content/docs/get-started/_meta.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
["do-existing", "SQLite"],
3232
["bun-sqlite-new", "SQLite"],
3333
["bun-sqlite-existing", "SQLite"],
34+
["bun-sql-new", "PostgreSQL"],
35+
["bun-sql-existing", "PostgreSQL"],
3436
["expo-new", "Native SQLite"],
3537
["expo-existing", "Native SQLite"],
3638
["op-sqlite-new", "Native SQLite"],
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import Npm from '@mdx/Npm.astro';
2+
import Npx from '@mdx/Npx.astro';
3+
import Callout from '@mdx/Callout.astro';
4+
import Prerequisites from "@mdx/Prerequisites.astro";
5+
import CodeTabs from "@mdx/CodeTabs.astro";
6+
import WhatsNextPostgres from "@mdx/WhatsNextPostgres.astro";
7+
import Breadcrumbs from '@mdx/Breadcrumbs.astro';
8+
import FileStructure from '@mdx/get-started/FileStructure.mdx';
9+
import InstallPackages from '@mdx/get-started/InstallPackages.mdx';
10+
import SetupConfig from '@mdx/get-started/SetupConfig.mdx';
11+
import TransferCode from '@mdx/get-started/TransferCode.mdx';
12+
import QueryDatabase from '@mdx/get-started/QueryDatabase.mdx';
13+
import QueryDatabaseUpdated from '@mdx/get-started/QueryDatabaseUpdated.mdx';
14+
import RunFile from '@mdx/get-started/RunFile.mdx';
15+
import ApplyChanges from '@mdx/get-started/ApplyChanges.mdx';
16+
import SetupEnv from '@mdx/get-started/SetupEnv.mdx';
17+
import IntrospectPostgreSQL from '@mdx/get-started/postgresql/IntrospectPostgreSQL.mdx';
18+
import ConnectBun from '@mdx/get-started/postgresql/ConnectBun.mdx';
19+
import UpdateSchema from '@mdx/get-started/postgresql/UpdateSchema.mdx';
20+
21+
<Breadcrumbs/>
22+
23+
# Get Started with Drizzle and SQLite in existing project
24+
25+
<Prerequisites>
26+
- **dotenv** - package for managing environment variables - [read here](https://www.npmjs.com/package/dotenv)
27+
- **bun** - javaScript all-in-one toolkit - [read here](https://bun.sh/)
28+
- **Bun SQL** - native bindings for working with PostgreSQL databases - [read here](https://bun.sh/docs/api/sql)
29+
</Prerequisites>
30+
31+
<FileStructure />
32+
33+
#### Step 1 - Install required packages
34+
35+
<Npm>
36+
drizzle-orm dotenv
37+
-D drizzle-kit @types/bun
38+
</Npm>
39+
40+
#### Step 2 - Setup connection variables
41+
42+
<SetupEnv env_variable='DATABASE_URL' />
43+
44+
#### Step 3 - Setup Drizzle config file
45+
46+
<SetupConfig dialect='postgresql' env_variable='DATABASE_URL'/>
47+
48+
#### Step 4 - Introspect your database
49+
50+
<IntrospectPostgreSQL/>
51+
52+
#### Step 5 - Transfer code to your actual schema file
53+
54+
<TransferCode/>
55+
56+
#### Step 6 - Connect Drizzle ORM to the database
57+
58+
<ConnectBun/>
59+
60+
#### Step 7 - Query the database
61+
62+
<QueryDatabase dialect='bun-sql' env_variable='DATABASE_URL' />
63+
64+
#### Step 8 - Run index.ts file
65+
66+
To run a script with `bun`, use the following command:
67+
```bash copy
68+
bun src/index.ts
69+
```
70+
71+
#### Step 9 - Update your table schema (optional)
72+
73+
<UpdateSchema/>
74+
75+
#### Step 9 - Applying changes to the database (optional)
76+
77+
<ApplyChanges/>
78+
79+
#### Step 10 - Query the database with a new field (optional)
80+
81+
<QueryDatabaseUpdated dialect='bun-sql' env_variable='DATABASE_URL' />
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import Npm from '@mdx/Npm.astro';
2+
import Npx from '@mdx/Npx.astro';
3+
import Callout from '@mdx/Callout.astro';
4+
import Prerequisites from "@mdx/Prerequisites.astro";
5+
import CodeTabs from "@mdx/CodeTabs.astro";
6+
import WhatsNextPostgres from "@mdx/WhatsNextPostgres.astro";
7+
import Breadcrumbs from '@mdx/Breadcrumbs.astro';
8+
import FileStructure from '@mdx/get-started/FileStructure.mdx';
9+
import InstallPackages from '@mdx/get-started/InstallPackages.mdx';
10+
import SetupConfig from '@mdx/get-started/SetupConfig.mdx';
11+
import TransferCode from '@mdx/get-started/TransferCode.mdx';
12+
import QueryDatabase from '@mdx/get-started/QueryDatabase.mdx';
13+
import QueryDatabaseUpdated from '@mdx/get-started/QueryDatabaseUpdated.mdx';
14+
import RunFile from '@mdx/get-started/RunFile.mdx';
15+
import ApplyChanges from '@mdx/get-started/ApplyChanges.mdx';
16+
import SetupEnv from '@mdx/get-started/SetupEnv.mdx';
17+
import CreateTable from '@mdx/get-started/postgresql/CreateTable.mdx';
18+
import ConnectBun from '@mdx/get-started/postgresql/ConnectBun.mdx';
19+
20+
<Breadcrumbs/>
21+
22+
# Get Started with Drizzle and Bun:SQLite
23+
24+
<Prerequisites>
25+
- **bun** - javaScript all-in-one toolkit - [read here](https://bun.sh/)
26+
- **Bun SQL** - native bindings for working with PostgreSQL databases - [read here](https://bun.sh/docs/api/sql)
27+
</Prerequisites>
28+
29+
<FileStructure />
30+
31+
#### Step 1 - Install required packages
32+
<Npm>
33+
drizzle-orm
34+
-D drizzle-kit @types/bun
35+
</Npm>
36+
37+
#### Step 2 - Setup connection variables
38+
39+
<SetupEnv env_variable='DATABASE_URL' />
40+
41+
#### Step 3 - Connect Drizzle ORM to the database
42+
43+
<ConnectBun/>
44+
45+
#### Step 4 - Create a table
46+
47+
<CreateTable/>
48+
49+
#### Step 5 - Setup Drizzle config file
50+
51+
<SetupConfig dialect='postgresql' env_variable='DATABASE_URL'/>
52+
53+
#### Step 6 - Applying changes to the database
54+
55+
<ApplyChanges />
56+
57+
#### Step 7 - Seed and Query the database
58+
59+
<QueryDatabase dialect='bun-sql' env_variable='DATABASE_URL'/>
60+
61+
#### Step 8 - Run index.ts file
62+
63+
To run a script with `bun`, use the following command:
64+
```bash copy
65+
bun src/index.ts
66+
```

src/content/docs/get-started/bun-sqlite-existing.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ DB_FILE_NAME=mydb.sqlite
6868

6969
#### Step 7 - Query the database
7070

71-
<QueryDatabase dialect='bun:sqlite' env_variable='DB_FILE_NAME' />
71+
<QueryDatabase dialect='bun-sqlite' env_variable='DB_FILE_NAME' />
7272

7373
#### Step 8 - Run index.ts file
7474

@@ -87,4 +87,4 @@ bun src/index.ts
8787

8888
#### Step 10 - Query the database with a new field (optional)
8989

90-
<QueryDatabaseUpdated dialect='bun:sqlite' env_variable='DB_FILE_NAME' />
90+
<QueryDatabaseUpdated dialect='bun-sqlite' env_variable='DB_FILE_NAME' />

src/content/docs/get-started/bun-sqlite-new.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ DB_FILE_NAME=mydb.sqlite
6363

6464
#### Step 7 - Seed and Query the database
6565

66-
<QueryDatabase dialect='bun:sqlite' env_variable='DB_FILE_NAME'/>
66+
<QueryDatabase dialect='bun-sqlite' env_variable='DB_FILE_NAME'/>
6767

6868
#### Step 8 - Run index.ts file
6969

src/mdx/GetStartedLinks/data.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,27 @@ export const getStartedItems: GetStartedItems = [
166166
},
167167
},
168168
},
169+
{
170+
name: "Bun SQL",
171+
path: {
172+
existing: "/docs/get-started/bun-sql-existing",
173+
new: "/docs/get-started/bun-sql-new",
174+
},
175+
icon: {
176+
light: {
177+
path: "/public/svg/bun.svg",
178+
style: {
179+
width: 20,
180+
},
181+
},
182+
dark: {
183+
path: "/public/svg/bun.svg",
184+
style: {
185+
width: 20,
186+
},
187+
},
188+
},
189+
},
169190
],
170191
},
171192
{
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import CodeTabs from "@mdx/CodeTabs.astro";
2+
3+
Create a `index.ts` file in the `src` directory and initialize the connection:
4+
5+
<CodeTabs items={["bun sql", "bun sql with config"]}>
6+
```typescript copy
7+
import 'dotenv/config';
8+
import { drizzle } from 'drizzle-orm/bun-sql';
9+
10+
const db = drizzle(process.env.DATABASE_URL!);
11+
```
12+
```typescript copy
13+
import 'dotenv/config';
14+
import { drizzle } from 'drizzle-orm/bun-sql';
15+
16+
// You can specify any property from the bun sql connection options
17+
const db = drizzle({ connection: { url: process.env.DATABASE_URL! }});
18+
```
19+
</CodeTabs>
20+
21+
If you need to provide your existing driver:
22+
```typescript copy
23+
import 'dotenv/config';
24+
import { drizzle } from 'drizzle-orm/bun-sql';
25+
import { SQL } from 'bun';
26+
27+
const client = new SQL(process.env.DB_FILE_NAME!);
28+
const db = drizzle({ client });
29+
```

src/mdx/get-started/sqlite/ConnectBun.mdx

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

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

5-
<CodeTabs items={["libsql", "libsql with config"]}>
5+
<CodeTabs items={["bun:sqlite", "bun:sqlite with config"]}>
66
```typescript copy
77
import 'dotenv/config';
88
import { drizzle } from 'drizzle-orm/bun-sqlite';
@@ -13,7 +13,7 @@ const db = drizzle(process.env.DB_FILE_NAME!);
1313
import 'dotenv/config';
1414
import { drizzle } from 'drizzle-orm/bun-sqlite';
1515

16-
// You can specify any property from the libsql connection options
16+
// You can specify any property from the bun:sql connection options
1717
const db = drizzle({ connection: { source: process.env.DB_FILE_NAME! }});
1818
```
1919
</CodeTabs>

0 commit comments

Comments
 (0)