-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prisma integration #405
prisma integration #405
Conversation
@yusukebe Do you mind if I do a code review here? |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Here are my suggestions, we can also see if @yusukebe agrees with my updates if you'd like
Update:
I meant to hit request changes, I clicked approve on accident.
examples/prisma.md
Outdated
@@ -0,0 +1,116 @@ | |||
# Prisma |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update heading:
"Using Prisma on Cloudflare Workers" or something similar
examples/prisma.md
Outdated
- Enable Accelerate | ||
- Enable Driver Adapters | ||
|
||
### Start Prisma |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the second heading for all the sections so and I would say install or setup instead of start:
## Install Prisma
examples/prisma.md
Outdated
There are two ways to use Prisma in your Cloudflare Workers: | ||
|
||
- Enable Accelerate | ||
- Enable Driver Adapters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this tutorial does not have the driver adapter section I would update this text a little. Something like this:
"There are two ways to use Prisma with Cloudflare Workers, we will be using Prisma Accelerate, but you can also use the Prisma Driver Adapter" and add a link there to the driver adapters instead of at the bottom.
examples/prisma.md
Outdated
First, start Prisma on your Hono Cloudflare Workers. Here, I am using neon.tech as my PostgreSQL database, but you can use whichever database suits your project. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Change "start" to "install".
- For neon say
I am using the [neon.tech](https://neon.tech/) free tier
...
examples/prisma.md
Outdated
```ts | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
directUrl = env("DIRECT_URL") | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add code block like above
examples/prisma.md
Outdated
```ts | ||
import { PrismaClient } from '@prisma/client/edge' | ||
import { withAccelerate } from '@prisma/extension-accelerate' | ||
|
||
export const getPrisma = (database_url: string) => { | ||
const prisma = new PrismaClient({ | ||
datasourceUrl: database_url, | ||
}).$extends(withAccelerate()); | ||
return prisma | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add code block
examples/prisma.md
Outdated
```ts | ||
import { Hono } from 'hono'; | ||
import { sign, verify } from 'hono/jwt'; | ||
import { getPrisma } from '../usefulFun/prismaFun'; | ||
|
||
// Create the main Hono app | ||
const app = new Hono<{ | ||
Bindings: { | ||
DATABASE_URL: string | ||
JWT_SECRET: string | ||
}, | ||
Variables: { | ||
userId: string, | ||
} | ||
}>(); | ||
|
||
app.post('/', async (c) => { | ||
// Now you can use it wherever you want | ||
const prisma = getPrisma(c.env?.DATABASE_URL); | ||
}); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add code block
examples/prisma.md
Outdated
# Enable Driver Adapters | ||
|
||
To enable [Database Driver](https://www.prisma.io/docs/orm/overview/databases/database-drivers), read the documentation. | ||
|
||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can now be removed since we simplified it above
package-lock.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file can be deleted, there is no lock file added to this repo
@NicoPlyley hi bro, please check out the new update that i made, bro i am seriously sorry for making so much mistake but thanks so much for your greate help, |
@imran1khan |
updated syntex mistake new syntex added
@NicoPlyley bro, thanks for your suggestion, i have added the |
package-lock.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this file from the PR? It's unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi, @yusukebe i have removed the package.-lock.json, as you asked.
Sorry for the late reply.
Yeah! |
examples/prisma.md
Outdated
@@ -0,0 +1,118 @@ | |||
# Using Prisma on Cloudflare Workers | |||
|
|||
There are two ways to use Prisma with Cloudflare Workers, we will be using Prisma Accelerate, but you can also use the Prisma [Driver Adapter](https://www.prisma.io/docs/orm/overview/databases/database-drivers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add .
to last.
examples/prisma.md
Outdated
|
||
Go to [neon.tech](https://neon.tech/) and create a free PostgreSQL database. | ||
|
||
```ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be bash
instead of ts
.
examples/prisma.md
Outdated
|
||
Create a function like this, which you can use in your project later: | ||
::: code-group | ||
```ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding the file name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yusukebe, bro, I have changed all the necessary things that you asked, but I did not mention the file name because we can make this function anywhere we want, so it's not file-specific. You can make this in your root folder and use it anywhere you want, so I am not sure what file name to put here. If you want me to write that in detail, let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the main file you can call index.ts
and this file you can name it whatever the import is on the index.ts file. That way it's clear to people that two separate files are being working in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yusukebe
bro, can i name the main working file as main.ts
and the function file as index.ts
,
or the main working file as index.ts
and the function file as prismafunction.ts
Hey @imran1khan ! This is great! I've left some comments. Please check them. |
examples/prisma.md
Outdated
To setup Accelerate, go to [Prisma Accelerate](https://www.prisma.io/data-platform/accelerate?via=start&gad_source=1&gclid=CjwKCAjwvIWzBhAlEiwAHHWgvX8l8e7xQtqurVYanQ6LmbNheNvCB-4FL0G6BFEfPrUdGyH3qSllqxoCXDoQAvD_BwE) and log in. | ||
|
||
After logging in, you will be taken to a page where you can create a new Accelerate project. and log in or register for free | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update this to
To setup Accelerate, go to [Prisma Accelerate](https://www.prisma.io/data-platform/accelerate?via=start&gad_source=1&gclid=CjwKCAjwvIWzBhAlEiwAHHWgvX8l8e7xQtqurVYanQ6LmbNheNvCB-4FL0G6BFEfPrUdGyH3qSllqxoCXDoQAvD_BwE) and log in or register for free.
After logging in, you will be taken to a page where you can create a new Accelerate project.
@imran1khan I added three things. I checked over it a few times I think it should be good after that. Yusuke will check again as well. Thanks for continuing and update this and contributing! |
@NicoPlyley , thnaks bro for taking your time and helping me, i am new to this, and i am very glad that you are so patience with me. so thanks alot. and let me know for some new addition |
Hey @imran1khan Please check my comment! |
@yusukebe, bro i have added the main working file as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Gooood! Thank you for your contribution! @NicoPlyley also thank you for reviewing. Let's go with it 🎉 |
@yusukebe thanks bro, i really appreciate your work and your help |
issue #384
bro, if you need any help feel free to contact, i have made the nessery changes, hopefully you are going to like it
i have added a doc for prisma installation, i hope it's going to be helpfull for someone who want's to know how to install prisma in cloudflare workers, if you like my work feel free to contact me,
i have added docs related to how we can use prisma accelerate but i have not added any doc, on how we can use prisma using Database driver, because it's very easy to do and anyone can read the doc link that i have provied and understand this