Skip to content
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

Merged
merged 5 commits into from
Jun 21, 2024
Merged

prisma integration #405

merged 5 commits into from
Jun 21, 2024

Conversation

imran1khan
Copy link
Contributor

@imran1khan imran1khan commented Jun 19, 2024

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

@NicoPlyley
Copy link
Contributor

@yusukebe Do you mind if I do a code review here?
I have a few recommendations and updates.

@imran1khan
Copy link
Contributor Author

@NicoPlyley bro feel free to add your ideas, it would be a great helpand learning

Copy link
Contributor

@NicoPlyley NicoPlyley left a 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.

.vitepress/config.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,116 @@
# Prisma
Copy link
Contributor

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

- Enable Accelerate
- Enable Driver Adapters

### Start Prisma
Copy link
Contributor

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

Comment on lines 3 to 6
There are two ways to use Prisma in your Cloudflare Workers:

- Enable Accelerate
- Enable Driver Adapters
Copy link
Contributor

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.

Comment on lines 10 to 8
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.

Copy link
Contributor

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...

Comment on lines 62 to 76
```ts
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
```
Copy link
Contributor

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

Comment on lines 76 to 91
```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
}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add code block

Comment on lines 90 to 117
```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);
});
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add code block

Comment on lines 112 to 116
# Enable Driver Adapters

To enable [Database Driver](https://www.prisma.io/docs/orm/overview/databases/database-drivers), read the documentation.

---
Copy link
Contributor

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

Copy link
Contributor

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

@imran1khan
Copy link
Contributor Author

@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,
and if i made some mistake again then feel free to currect me.
thanks so much.
one question i had was, why we have to make another .dev.vars file because when we run prisma init it's going to create .env file so, do we have to delete that .env file after coping the content into the .dev.vars? because i thought prisma in not going to run without .env file

@NicoPlyley
Copy link
Contributor

@imran1khan
First off you did a great job. Most the updates were just to add a bit of simplicity.
I am unsure about the .env file with prisma so if the cli needs it then go ahead a leave that in. You might want to specify that in there too.

updated

syntex mistake

new syntex added
@imran1khan
Copy link
Contributor Author

imran1khan commented Jun 19, 2024

@NicoPlyley bro, thanks for your suggestion, i have added the .env and explained it too. i know your time is precious, but let me know if you want some outher correction. and also i have squash the commits so,i thought it's good to let you know

Copy link
Member

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.

Copy link
Contributor Author

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.

@yusukebe
Copy link
Member

Sorry for the late reply.

@yusukebe Do you mind if I do a code review here?

Yeah!

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add . to last.


Go to [neon.tech](https://neon.tech/) and create a free PostgreSQL database.

```ts
Copy link
Member

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.


Create a function like this, which you can use in your project later:
::: code-group
```ts
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the tab names are ts:

CleanShot 2024-06-21 at 15 05 55@2x

How about adding a file name like this?

::: code-group
```ts [filename.ts]

Copy link
Contributor Author

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

examples/prisma.md Outdated Show resolved Hide resolved
@yusukebe
Copy link
Member

Hey @imran1khan !

This is great! I've left some comments. Please check them.

Comment on lines 18 to 21
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

Copy link
Contributor

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.

examples/prisma.md Outdated Show resolved Hide resolved
@NicoPlyley
Copy link
Contributor

@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!

@imran1khan
Copy link
Contributor Author

@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

@yusukebe
Copy link
Member

Hey @imran1khan

Please check my comment!

@imran1khan
Copy link
Contributor Author

@yusukebe, bro i have added the main working file as index.ts and the function file from which i am importing the function as prismaFunction.ts, i hope it works. but let me know your suggestion

Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe
Copy link
Member

@imran1khan

Gooood! Thank you for your contribution!

@NicoPlyley also thank you for reviewing.

Let's go with it 🎉

@yusukebe yusukebe merged commit 43fb25e into honojs:main Jun 21, 2024
@imran1khan
Copy link
Contributor Author

@yusukebe thanks bro, i really appreciate your work and your help

@imran1khan imran1khan deleted the prismaInte branch June 21, 2024 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants