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
You'll need to answer a few questions while setting up your Prisma Postgres database. Select the region closest to your location and a memorable name for your database like "My Astro Project"
@@ -74,9 +74,9 @@ In the `prisma/schema.prisma` file, add the following models and change the gene
74
74
75
75
```prisma file=prisma/schema.prisma
76
76
generator client {
77
-
//edit-next-line
78
-
provider = "prisma-client"
79
-
output = "../src/generated/prisma"
77
+
provider = "prisma-client"
78
+
engineType = "client"
79
+
output = "../prisma/generated"
80
80
}
81
81
82
82
datasource db {
@@ -119,7 +119,7 @@ Let's add some seed data to populate the database with sample users and posts.
119
119
Create a new file called `seed.ts` in the `prisma/` directory:
@@ -254,7 +282,7 @@ We recommend using a connection pooler (like [Prisma Accelerate](https://www.pri
254
282
If you choose not to use one, **avoid** instantiating `PrismaClient` globally in long-lived environments. Instead, create and dispose of the client per request to prevent exhausting your database connections.
255
283
:::
256
284
257
-
### 3.2. Create an API route
285
+
### 3.3. Create an API route
258
286
259
287
An API route is the best way to fetch data from your database in an Astro app.
260
288
@@ -267,7 +295,7 @@ touch src/pages/api/users.ts
267
295
268
296
Now, create a GET route that fetches the `Users` data from your database, making sure to include each user's `Posts` by adding them to the `include` field:
Next, you'll call this route from the `index.astro` file and display it.
313
+
### 3.4. Fetch the data from the API route (Recommended Method)
286
314
287
-
### 3.3. Fetch the data from the API route
315
+
Instead of using `fetch()` with HTTP requests, Astro recommends importing endpoint functions directly. This approach is more efficient and avoids URL parsing issues.
288
316
289
-
Start by create a new type that combines the `User` and `Post` models called `UserWithPosts`:
317
+
Start by creating a new type that combines the `User` and `Post` models called `UserWithPosts`:
290
318
291
319
```tsx file=src/pages/index.astro
292
320
---
293
321
//add-start
294
-
importtype { User, Post } from"../generated/prisma/client.js";
295
-
typeUserWithPosts=User& { posts:Post[] };
296
-
//add-end
297
-
---
322
+
importtype { User, Post } from"../../prisma/generated/client";
0 commit comments