Skip to content

Commit 41f5261

Browse files
committed
Added drizzle docs and updated prisma
1 parent ce1a54e commit 41f5261

File tree

3 files changed

+158
-8
lines changed

3 files changed

+158
-8
lines changed

docs/guides/frameworks/drizzle.mdx

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
title: "Drizzle setup guide"
3+
sidebarTitle: "Drizzle setup guide"
4+
description: "This guide will show you how to set up Drizzle ORM with Trigger.dev"
5+
icon: "D"
6+
---
7+
8+
import Prerequisites from "/snippets/framework-prerequisites.mdx";
9+
import CliInitStep from "/snippets/step-cli-init.mdx";
10+
import CliDevStep from "/snippets/step-cli-dev.mdx";
11+
import CliRunTestStep from "/snippets/step-run-test.mdx";
12+
import CliViewRunStep from "/snippets/step-view-run.mdx";
13+
import UsefulNextSteps from "/snippets/useful-next-steps.mdx";
14+
15+
## Overview
16+
17+
This guide will show you how to set up [Drizzle ORM](https://orm.drizzle.team/) with Trigger.dev, test and view an example task run.
18+
19+
## Prerequisites
20+
21+
- An existing Node.js project with a `package.json` file
22+
- Ensure TypeScript is installed
23+
- A [PostgreSQL](https://www.postgresql.org/) database server running locally, or accessible via a connection string
24+
- Drizzle ORM [installed and initialized](https://orm.drizzle.team/docs/get-started) in your project
25+
- A `DATABASE_URL` environment variable set in your `.env` file, pointing to your PostgreSQL database (e.g. `postgresql://user:password@localhost:5432/dbname`)
26+
27+
## Initial setup (optional)
28+
29+
Follow these steps if you don't already have Trigger.dev set up in your project.
30+
31+
<Steps>
32+
<CliInitStep />
33+
<CliDevStep />
34+
<CliRunTestStep />
35+
<CliViewRunStep />
36+
</Steps>
37+
38+
## Creating a task using Drizzle and deploying it to production
39+
40+
<Steps>
41+
<Step title="The task using Drizzle">
42+
43+
First, create a new task file in your `trigger` folder.
44+
45+
This is a simple task that will add a new user to your database, we will call it `drizzle-add-new-user`.
46+
47+
<Note>
48+
For this task to work correctly, you will need to have a `users` table schema defined with Drizzle
49+
that includes `name`, `age` and `email` fields.
50+
</Note>
51+
52+
```ts /trigger/drizzle-add-new-user.ts
53+
import { eq } from "drizzle-orm";
54+
import { task } from "@trigger.dev/sdk/v3";
55+
import { users } from "src/db/schema";
56+
import { drizzle } from "drizzle-orm/node-postgres";
57+
58+
// Initialize Drizzle client
59+
const db = drizzle(process.env.DATABASE_URL!);
60+
61+
export const addNewUser = task({
62+
id: "drizzle-add-new-user",
63+
run: async (payload: typeof users.$inferInsert) => {
64+
// Create new user
65+
const [user] = await db.insert(users).values(payload).returning();
66+
67+
return {
68+
createdUser: user,
69+
message: "User created and updated successfully",
70+
};
71+
},
72+
});
73+
```
74+
75+
</Step>
76+
<Step title="Configuring the build">
77+
78+
Next, in your `trigger.config.js` file, add `pg` to the `externals` array. `pg` is a non-blocking PostgreSQL client for Node.js.
79+
80+
It is marked as an external to ensure that it is not bundled into the task's bundle, and instead will be installed and loaded from `node_modules` at runtime.
81+
82+
```js /trigger.config.js
83+
import { defineConfig } from "@trigger.dev/sdk/v3";
84+
85+
export default defineConfig({
86+
project: "<project ref>", // Your project reference
87+
// Your other config settings...
88+
build: {
89+
externals: ["pg"],
90+
},
91+
});
92+
```
93+
94+
</Step>
95+
96+
<Step title="Deploying your task">
97+
Once the build configuration is added, you can now deploy your task using the Trigger.dev CLI.
98+
99+
<CodeGroup>
100+
101+
```bash npm
102+
npx trigger.dev@latest deploy
103+
```
104+
105+
```bash pnpm
106+
pnpm dlx trigger.dev@latest deploy
107+
```
108+
109+
```bash yarn
110+
yarn dlx trigger.dev@latest deploy
111+
```
112+
113+
</CodeGroup>
114+
115+
</Step>
116+
117+
<Step title="Adding your DATABASE_URL environment variable to Trigger.dev">
118+
119+
In your Trigger.dev dashboard sidebar click "Environment Variables" <Icon icon="circle-1" iconType="solid" size={20} color="A8FF53" />, and then the "New environment variable" button <Icon icon="circle-2" iconType="solid" size={20} color="A8FF53" />.
120+
121+
![Environment variables page](/images/environment-variables-page.jpg)
122+
123+
You can add values for your local dev environment, staging and prod. in this case we will add the `DATABASE_URL` for the production environment.
124+
125+
![Environment variables
126+
page](/images/environment-variables-panel.jpg)
127+
128+
</Step>
129+
130+
<Step title="Running your task">
131+
132+
To test this task, go to the 'test' page in the Trigger.dev dashboard and run the task with the following payload:
133+
134+
```json
135+
{
136+
"name": "<a-name>", // e.g. "John Doe"
137+
"age": "<an-age>", // e.g. 25
138+
"email": "<an-email>" // e.g. "john@doe.test"
139+
}
140+
```
141+
142+
Congratulations! You should now see a new completed run, and a new user with the credentials you provided should be added to your database.
143+
144+
</Step>
145+
146+
</Steps>
147+
148+
<UsefulNextSteps />

docs/guides/frameworks/prisma.mdx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Prisma setup guide"
33
sidebarTitle: "Prisma setup guide"
4-
description: "This guide will show you how to setup Prisma with Trigger.dev"
4+
description: "This guide will show you how to set up Prisma with Trigger.dev"
55
icon: "Triangle"
66
---
77

@@ -14,7 +14,7 @@ import UsefulNextSteps from "/snippets/useful-next-steps.mdx";
1414

1515
## Overview
1616

17-
This guide will show you how to set up Prisma with Trigger.dev, test and view an example task run.
17+
This guide will show you how to set up [Prisma](https://www.prisma.io/) with Trigger.dev, test and view an example task run.
1818

1919
## Prerequisites
2020

@@ -24,7 +24,9 @@ This guide will show you how to set up Prisma with Trigger.dev, test and view an
2424
- Prisma ORM [installed and initialized](https://www.prisma.io/docs/getting-started/quickstart) in your project
2525
- A `DATABASE_URL` environment variable set in your `.env` file, pointing to your PostgreSQL database (e.g. `postgresql://user:password@localhost:5432/dbname`)
2626

27-
## Initial setup
27+
## Initial setup (optional)
28+
29+
Follow these steps if you don't already have Trigger.dev set up in your project.
2830

2931
<Steps>
3032
<CliInitStep />
@@ -151,8 +153,7 @@ With the build extension and task configured, you can now deploy your task using
151153

152154
<Step title="Adding your DATABASE_URL environment variable to Trigger.dev">
153155

154-
In the sidebar select the "Environment Variables" page, then press the "New environment variable"
155-
button. ![Environment variables page](/images/environment-variables-page.jpg)
156+
In your Trigger.dev dashboard sidebar click "Environment Variables" <Icon icon="circle-1" iconType="solid" size={20} color="A8FF53" />, and then the "New environment variable" button <Icon icon="circle-2" iconType="solid" size={20} color="A8FF53" />.
156157

157158
You can add values for your local dev environment, staging and prod. in this case we will add the `DATABASE_URL` for the production environment.
158159

@@ -167,9 +168,9 @@ You can add values for your local dev environment, staging and prod. in this cas
167168

168169
```json
169170
{
170-
"name": "John Doe",
171-
"email": "john@doe.test",
172-
"id": 12345
171+
"name": "<a-name>", // e.g. "John Doe"
172+
"email": "<a-email>", // e.g. "john@doe.test"
173+
"id": <a-number> // e.g. 12345
173174
}
174175
```
175176

docs/mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@
299299
"group": "Guides",
300300
"pages": [
301301
"guides/frameworks/prisma",
302+
"guides/frameworks/drizzle",
302303
"guides/frameworks/sequin",
303304
{
304305
"group": "Supabase",

0 commit comments

Comments
 (0)