Skip to content

Commit 7856781

Browse files
mhartingtonankur-archaidankmcalister
authored
Apply suggestions from code review
Co-authored-by: Ankur Datta <[email protected]> Co-authored-by: Aidan McAlister <[email protected]>
1 parent d51e0d0 commit 7856781

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

content/800-guides/390-hono.mdx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 'How to use Prisma ORM with Hono'
2+
title: 'How to use Prisma with Hono'
33
metaTitle: 'How to use Prisma ORM and Prisma Postgres with Hono'
44
description: 'Learn how to use Prisma ORM in a Hono app'
55
sidebar_label: 'Hono'
@@ -33,7 +33,7 @@ npm create hono@latest
3333
- *Which package manager do you want to use?* `npm`
3434
:::
3535

36-
## 2. Install and Configure Prisma
36+
## 2. Install and configure Prisma
3737

3838
### 2.1. Install dependencies
3939

@@ -209,9 +209,9 @@ And open Prisma Studio to inspect your data:
209209
npx prisma studio
210210
```
211211

212-
## 3. Integrate Prisma Into Hono
212+
## 3. Integrate Prisma into Hono
213213

214-
### 3.1. Create a Prisma Middleware
214+
### 3.1. Create a Prisma middleware
215215

216216
Inside of `/src`, create a `lib` directory and a `prisma.ts` file inside it. This file will be used to create and export your Prisma Client instance. Set up the Prisma client like this:
217217

@@ -283,20 +283,42 @@ import * as dotenv from 'dotenv';
283283
dotenv.config();
284284
```
285285

286-
Next, Hono needs additional types to to know that the `withPrisma` middleware will set a `prsima`
286+
Next, Hono needs additional types to to know that the `withPrisma` middleware will set a `prisma`
287287
key on the Hono Context
288288

289289
```ts file=src/index.ts
290-
import type { PrismaClient } from './generated/prisma/client.js';
290+
import { Hono } from "hono";
291+
import { serve } from "@hono/node-server";
292+
// add-next-line
293+
import type { PrismaClient } from "./generated/prisma/client.js";
291294

295+
import * as dotenv from "dotenv";
296+
dotenv.config();
297+
298+
// add-start
292299
type ContextWithPrisma = {
293300
Variables: {
294301
prisma: PrismaClient;
295302
};
296303
};
304+
// add-end
297305

306+
// edit-next-line
298307
const app = new Hono<ContextWithPrisma>();
299-
```
308+
309+
app.get("/", (c) => {
310+
return c.text("Hello Hono!");
311+
});
312+
313+
serve(
314+
{
315+
fetch: app.fetch,
316+
port: 3000,
317+
},
318+
(info) => {
319+
console.log(`Server is running on http://localhost:${info.port}`);
320+
}
321+
);
300322

301323

302324
### 3.3. Create A GET Route

0 commit comments

Comments
 (0)