You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/example-projects/turborepo-monorepo-prisma.mdx
+84-6Lines changed: 84 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,17 +6,17 @@ description: "Two example projects demonstrating how to use Prisma and Trigger.d
6
6
7
7
## Overview
8
8
9
-
These examples demonstrate how to use Prisma and Trigger.dev in a Turborepo monorepo.
9
+
These examples demonstrate two different ways to use Prisma and Trigger.dev in a Turborepo monorepo. They both trigger a task from a Next.js app using a server action, and then use Prisma to add a user to a database table, however they differ in how Trigger.dev is installed and configured.
10
+
11
+
- Example 1: Turborepo monorepo demo with Trigger.dev and Prisma packages
12
+
- Example 2: Turborepo monorepo demo with a Prisma package and Trigger.dev installed in a Next.js app
10
13
11
14
<Note>
12
15
13
16
You can either fork the repos below, or simply check out the project structures and code to get an idea of how to set up Trigger.dev in your own monorepos.
14
17
15
18
</Note>
16
19
17
-
- Example 1: Turborepo monorepo demo with Trigger.dev and Prisma packages
18
-
- Example 2: Turborepo monorepo demo with a Prisma package and Trigger.dev installed in a Next.js app
19
-
20
20
## Example 1: Turborepo monorepo demo with Trigger.dev and Prisma packages
21
21
22
22
This simple example demonstrates how to use Trigger.dev and Prisma as packages inside a monorepo created with Turborepo. The Trigger.dev task is triggered by a button click in a Next.js app which triggers the task via a server action.
@@ -26,7 +26,7 @@ This simple example demonstrates how to use Trigger.dev and Prisma as packages i
26
26
Fork the GitHub repo below to get started with this example project.
27
27
28
28
<Card
29
-
title="Check out the Turborepo monorepo demo with Trigger.dev and Prisma packages repo"
29
+
title="Check out the Turborepo monorepo demo with Trigger.dev and Prisma packages"
@@ -44,6 +44,8 @@ Fork the GitHub repo below to get started with this example project.
44
44
45
45
### Project structure
46
46
47
+
Simplified project structure for this example:
48
+
47
49
```
48
50
|
49
51
| — apps/
@@ -114,4 +116,80 @@ You must include the version of Prisma you are using in the `trigger.config.ts`
114
116
115
117
### Running the example
116
118
117
-
To run this example, check out the full instructions [in the repo](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package).
119
+
To run this example, check out the full instructions [in the GitHub repo README file](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package/README.md).
120
+
121
+
## Example 2: Turborepo monorepo demo with a Prisma package and Trigger.dev installed in a Next.js app
122
+
123
+
This example demonstrates how to use Trigger.dev and Prisma in a monorepo created with Turborepo. Prisma has been added as a package, and Trigger.dev has been installed in a Next.js app. The task is triggered by a button click in the app via a server action.
124
+
125
+
### GitHub repo
126
+
127
+
Fork the GitHub repo below to get started with this example project.
128
+
129
+
<Card
130
+
title="Check out the Turborepo monorepo demo with a Prisma package and Trigger.dev installed in a Next.js app repo"
Click here to view the full code for this project in our examples repository on GitHub. You can
135
+
fork it and use it as a starting point for your own project.
136
+
</Card>
137
+
138
+
### Features
139
+
140
+
- This monorepo has been created using the [Turborepo CLI](https://turbo.build/repo), following the official [Prisma and Turborepo docs](https://www.prisma.io/docs/guides/turborepo), and then adapted for use with Trigger.dev.
141
+
-[pnpm](https://pnpm.io/) has been used as the package manager.
142
+
- A database package (`@repo/db`) using [Prisma ORM](https://www.prisma.io/docs/orm/) is used to interact with the database. You can use any popular Postgres database supported by Prisma, e.g. [Supabase](https://supabase.com/), [Neon](https://neon.tech/), etc.
143
+
- A [Next.js](https://nextjs.org/) example app (`apps/web`) to show how to trigger the task via a server action.
144
+
- Trigger.dev initialized and an `addNewUser` task created in the `web` app.
145
+
146
+
### Project structure
147
+
148
+
Simplified project structure for this example:
149
+
150
+
```
151
+
|
152
+
| — apps/
153
+
| | — web/ # Next.js frontend application
154
+
| | | — app/ # Next.js app router
155
+
| | | | — api/
156
+
| | | | | — actions.ts # Server actions for triggering tasks
157
+
| | | | — page.tsx # Main page with "Add new user" button
| — package.json # Root package.json with workspace config
177
+
```
178
+
179
+
## Relevant files and code
180
+
181
+
### Database package (`@repo/db`)
182
+
183
+
- Located in [`/packages/database/`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/packages/database/) and exported as `@repo/db`
184
+
- Schema defined in [`schema.prisma`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/packages/database/prisma/schema.prisma)
185
+
- Provides database access to other packages and apps
186
+
187
+
### Next.js app (`apps/web`)
188
+
189
+
- Contains Trigger.dev configuration in [`trigger.config.ts`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/apps/web/trigger.config.ts)
190
+
- Trigger.dev tasks are defined in [`src/trigger/`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/apps/web/src/trigger/) (e.g., [`addNewUser.ts`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/apps/web/src/trigger/addNewUser.ts))
191
+
- Demonstrates triggering tasks via server actions in [`app/api/actions.ts`](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/apps/web/app/api/actions.ts)
192
+
193
+
### Running the example
194
+
195
+
To run this example, check out the full instructions [in the GitHub repo README file](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-trigger/README.md).
0 commit comments