Serverless API with Cloudflare Workers (Hono, D1 & Drizzle ORM)

Ғылым және технология

Cloudflare Workers - a hot topic as of late but the one thing not many videos are covering is how to query a serverless database. In this video, we're setting up a Cloudflare D1 database and querying it using Drizzle ORM. The REST API is built using Hono for the routing and we have Bun as the package manager. Let me know if there are any other Cloudflare tools that interest you!
#cloudflare #bunjs #hono #drizzleorm
Source Code: github.com/cdbrw/cfw-bun-hono...
Set up Drizzle ORM: • Get Started With Drizz...
Deploy a Bun App: • Deploy a Bun API in Un...
➙ Blog: links.cdbrw.com/blog
➙ GitHub: links.cdbrw.com/github
➙ Twitter: links.cdbrw.com/x
👉 Support the channel: links.cdbrw.com/support
➙ My browser: links.cdbrw.com/browser
➙ Recording software: links.cdbrw.com/recording
➙ Microphone (US): links.cdbrw.com/mic-us
➙ Microphone (CA): links.cdbrw.com/mic-ca
00:00 Introduction
01:21 Setup
03:27 First Deploy
04:15 Dependencies
04:42 Database Create
05:16 Env Variables
07:20 Drizzle Setup
08:25 Querying Database
09:22 Local Migrations
10:07 Local DB Connection
10:33 Production Migrations
11:28 More Routes
12:23 Testing API

Пікірлер: 44

  • @dova5944
    @dova59442 ай бұрын

    Awesome video man, from the quality of this video I would have never guessed this is such a small channel. Keep up the good work!

  • @cdbrw

    @cdbrw

    2 ай бұрын

    Thanks your comment made my day 🙏 the goal is to make each video better than the last so hopefully its only up from here

  • @technoM4niac
    @technoM4niac2 ай бұрын

    Im glad to be early for the next big upcoming tech youtuber. Thanks for adding comments to your examples, helps to follow along 😎😎😎

  • @cdbrw

    @cdbrw

    2 ай бұрын

    Thanks, yea I figure I should add more comments to the videos 🤔

  • @cas818028
    @cas8180282 ай бұрын

    That cold start was brutal

  • @cdbrw

    @cdbrw

    2 ай бұрын

    after the first deploy?

  • @journeyofc6200

    @journeyofc6200

    19 күн бұрын

    wtf are you talking about?

  • @ustav_o
    @ustav_oАй бұрын

    that might've been the best tutorial i've ever seen

  • @cdbrw

    @cdbrw

    Ай бұрын

    thanks 🫶

  • @juniorxInnovationAcademy
    @juniorxInnovationAcademy26 күн бұрын

    Im trying to build a multi-tenant inventory and small business records management system on Cloudflare. I really hope it doesnt let me down. Thanks for this video and the one you did after this adding in Lucia. They've been really helpful

  • @rafamuttoni
    @rafamuttoni2 ай бұрын

    Great video, man! Thanks for making it.

  • @cdbrw

    @cdbrw

    2 ай бұрын

    Thanks for watching, glad you found it useful 🙏

  • @ayushrameja
    @ayushrameja2 ай бұрын

    Great video 🌟

  • @cdbrw

    @cdbrw

    2 ай бұрын

    thank you 🙏

  • @jacobtb1
    @jacobtb12 ай бұрын

    amazing vid, thanks

  • @cdbrw

    @cdbrw

    2 ай бұрын

    glad you found it useful 🙏

  • @DBDCheeto
    @DBDCheeto28 күн бұрын

    that was good

  • @rafalk0
    @rafalk02 ай бұрын

    Awesome video! What's that VS Code db plugin you're using?

  • @cdbrw

    @cdbrw

    2 ай бұрын

    Thanks! Its just called "Database Client", I think its one of the more popular ones

  • @flakybuild
    @flakybuildАй бұрын

    Great video 👌 Would you know a good way to run all of the pending migrations with drizzle in D1 so that one doesn't need to always explicitly specify them?

  • @cdbrw

    @cdbrw

    Ай бұрын

    I've actually been thinking about this and maybe I'll make a video on it once I figure it out. Check out this GitHub thread: github.com/drizzle-team/drizzle-orm/discussions/1388 I haven't tried the above so I can't say if it will work. The other idea I've been playing around with is using the bun shell to write a script which will execute each one by one. Will see if I can get anywhere with these 🤔

  • @VSIMadeIt
    @VSIMadeIt2 ай бұрын

    Intersted in seeing something like this with Turso instead of D1.

  • @cdbrw

    @cdbrw

    2 ай бұрын

    Noted, will work on the video soon 🫡

  • @4115steve
    @4115steveАй бұрын

    what other databases like d1 deploy to the edge? This seems like the best stack for a web app that uses edge with D1 and workers.

  • @cdbrw

    @cdbrw

    Ай бұрын

    There’s also Turso for sqlite and Neon for postgres. I’m sure there’s other ones too. Check out the video I made on Turso if you’re interested 👀

  • @illzcodes
    @illzcodesАй бұрын

    Have you figured out how to get drizzle studio to run? I keep getting an error even though my setup is exactly like this.

  • @cdbrw

    @cdbrw

    Ай бұрын

    I'm still waiting for a better way to allow for this. Basically as of right now the only way to really do this is to split up your drizzle config into a local version and a cloudflare version but I'll wait on a more official implementation. If you're looking to get it working right now though, I recommend going through this thread and checking out the blog posts aswell: github.com/drizzle-team/drizzle-orm/discussions/1545

  • @IanMathaiya
    @IanMathaiyaАй бұрын

    What are you using to highlight the errors like that 7:17?

  • @cdbrw

    @cdbrw

    Ай бұрын

    Its a vscode extension called "Error Lens"

  • @samijuniorkahil7914
    @samijuniorkahil79142 ай бұрын

    does drizzle create a new connection to the db on every request?

  • @cdbrw

    @cdbrw

    2 ай бұрын

    Since Cloudflare D1 is a serverless database, it doesn't require a persistent connection like a traditional database. You interact with it using HTTP-based APIs or through the D1 bindings available in Cloudflare Workers which eliminates the need for connection pooling and simplifies the handling of database operations. Drizzle just abstracts all these interactions for us and makes sure all operations are self-contained, without having to rely on persistent connections or stateful sessions.

  • @samijuniorkahil7914

    @samijuniorkahil7914

    2 ай бұрын

    @@cdbrw ah that makes sense

  • @frazuppi4897
    @frazuppi48972 ай бұрын

    how to have multiple routes in multiple files?

  • @cdbrw

    @cdbrw

    2 ай бұрын

    If let's say you had a `users` api and you wanted to split that up into its own router file, you would create it in lets say a users.ts file then create the router like so: const users = new Hono(); You then add whatever routes you want to it and export users at the bottom of the file. Now in your main index.ts, all you have to do is just import users and then: const api = new Hono(); api.route('/users', users); Hope this helps!

  • @frazuppi4897

    @frazuppi4897

    2 ай бұрын

    @@cdbrw Thank you so much :)

  • @PeterZhou-vi3ep
    @PeterZhou-vi3ep2 ай бұрын

    d1 is great, but it doesn't support transactions

  • @cdbrw

    @cdbrw

    2 ай бұрын

    Yea theres certain things like that where it shows its still very early days and not quite production ready yet but I still think overall it has the potential be really good

  • @iogilarb
    @iogilarbАй бұрын

    cloudflare?

  • @cdbrw

    @cdbrw

    Ай бұрын

    cloudflare.

  • @patrickjreid
    @patrickjreid8 күн бұрын

    I got to say, with all the cloudflare news lately I would avoid anything they do with every fiber of my being.

  • @everistusolumese9350

    @everistusolumese9350

    8 күн бұрын

    That is just your opinion.

Келесі