If you enjoyed watching this video, make sure to like and subscribe so you don't miss out on any future videos. Check out this video if you'd like to learn more about Neon database branching: ua-cam.com/video/j4Vak4J10KU/v-deo.html Drizzle ORM Docs: orm.drizzle.team/docs/overview Neon Serverless Driver: github.com/neondatabase/serverless
If you would like to do interactive transactions, you can use the websocket version of the driver. Here's an example: github.com/neondatabase/serverless/tree/main?tab=readme-ov-file#example-nodejs-with-poolconnect - Mahmoud
Hey man! Very nice video! I’m thinking to create some kind of project using CF! Can you share some ideas of costs that you have on CF! Just to have some knowledge about it! Another idea that can be a nice idea for a video, it’s a next-auth with this hono serverless api integration!
Hi, I have a suggestion with the Neon authorization 3rd party APPs part. I found that you authorized Cloudflare to read the Neon project, and then Cloudflare could fetch the DB password with such permissions. I think it's necessary to add a explicit hint at the authorization page, that the Read permission can see your DB password.
Hello can anyone please answer this, when i run npm create cloudflare --name and i select cloudflare workers , typescript, deploy no and when i go to vs code and run npm run dev it throws error errono -4095 i done everything uninstall Wrangler, install it again but it just doesn't work how can resolve this if anyone help
What would be the right way to handle the db initialisation? Do I write the two lines in every single api single I need the env variables (since we are using hono)? Do I create the db in a middleware and then add that to hono context? What is the right way here?
do i need to write this every endpoint need query/insert to db? const client = new Client({ connectionString: c.env.DATABASE_URL }); const db = drizzle(client); await client.connect();
Yes. In serverless environments such as Vercel Edge Functions or Cloudflare Workers, WebSocket connections can't outlive a single request. That means Pool or Client objects must be connected, used and closed within a single request handler. Don't create them outside a request handler; don't create them in one handler and try to reuse them in another; and to avoid exhausting available connections, don't forget to close them. Here's a code example github.com/neondatabase/serverless?tab=readme-ov-file#example-nodejs-with-poolconnect - Mahmoud
>connect to multiple frontend If you mean that different frontends can interact with the API, then yes. It's basically an API endpoint that any client can interact with - Mahmoud
Adding the db:generate command to package.json. I could not get the shortcut working that is demoed in the video I had to use drizzle-kit generate --dialect=postgresql --schema=./src/db/schema.ts just in case you run into the same issue great video tutorial
If you enjoyed watching this video, make sure to like and subscribe so you don't miss out on any future videos.
Check out this video if you'd like to learn more about Neon database branching: ua-cam.com/video/j4Vak4J10KU/v-deo.html
Drizzle ORM Docs: orm.drizzle.team/docs/overview
Neon Serverless Driver: github.com/neondatabase/serverless
Thank you for your clean explanation and taking the time to answer questions in comments below, its super helpful! 😁
thank you for these information i wish you will made a video about how we can handle transactions
If you would like to do interactive transactions, you can use the websocket version of the driver.
Here's an example: github.com/neondatabase/serverless/tree/main?tab=readme-ov-file#example-nodejs-with-poolconnect
- Mahmoud
Subscribing because the host is a cool guy
Hey man! Very nice video! I’m thinking to create some kind of project using CF! Can you share some ideas of costs that you have on CF! Just to have some knowledge about it! Another idea that can be a nice idea for a video, it’s a next-auth with this hono serverless api integration!
Hi, I have a suggestion with the Neon authorization 3rd party APPs part. I found that you authorized Cloudflare to read the Neon project, and then Cloudflare could fetch the DB password with such permissions. I think it's necessary to add a explicit hint at the authorization page, that the Read permission can see your DB password.
Can you tell how to access the env vars outside the get method? I read the docs but couldn't understand.
did you find out ?
You can’t, because the server might be dead, and needs to start, so access is done in the method (if I understood the GitHub issue correctly)
@@antonym00Yes, you're correct.
Hello can anyone please answer this, when i run npm create cloudflare --name and i select cloudflare workers , typescript, deploy no and when i go to vs code and run npm run dev it throws error errono -4095 i done everything uninstall Wrangler, install it again but it just doesn't work how can resolve this if anyone help
What would be the right way to handle the db initialisation? Do I write the two lines in every single api single I need the env variables (since we are using hono)?
Do I create the db in a middleware and then add that to hono context? What is the right way here?
do i need to write this every endpoint need query/insert to db?
const client = new Client({ connectionString: c.env.DATABASE_URL });
const db = drizzle(client);
await client.connect();
Yes. In serverless environments such as Vercel Edge Functions or Cloudflare Workers, WebSocket connections can't outlive a single request.
That means Pool or Client objects must be connected, used and closed within a single request handler. Don't create them outside a request handler; don't create them in one handler and try to reuse them in another; and to avoid exhausting available connections, don't forget to close them.
Here's a code example github.com/neondatabase/serverless?tab=readme-ov-file#example-nodejs-with-poolconnect
- Mahmoud
So we can use this to connect to multiple frontend? (eg. NextJS web app, React Native mobile app)
>connect to multiple frontend
If you mean that different frontends can interact with the API, then yes. It's basically an API endpoint that any client can interact with
- Mahmoud
Adding the db:generate command to package.json. I could not get the shortcut working that is demoed in the video I had to use drizzle-kit generate --dialect=postgresql --schema=./src/db/schema.ts just in case you run into the same issue great video tutorial