core icon indicating copy to clipboard operation
core copied to clipboard

Support Cloudflare Hyperdrive connection in Nuxt-hub

Open wldbest opened this issue 1 year ago • 1 comments

Can I use NuxtHub with Hyperdrive? I want to connect Postgresql in workers (for vector queries), but the only way seems to be using Cloudflare Hyperdrive.

When I try to use worker & Hyperdrive in Nuxt environment, local Postgres drivers like 'postgres, pg' seem to block the build process. So I couldn't succeed Nuxt + Hyperdrive in workers environment. (I remember it were win-socket errors. I host my Postgres in arm ubuntu docker at Oracle cloud (4 CPU, 24GB), local develop: windows10)

Is there any way to use Nuxt(NuxtHub) with Hyperdrive? Thanks in advance.

wldbest avatar Jul 25 '24 09:07 wldbest

I have not tried yet, adding the enhancement label and will take a look once available.

atinux avatar Aug 06 '24 15:08 atinux

To give an update, with the v0.7.5 you can now use the postgres package:

// server/api/products.get.ts
import postgres from 'postgres'

export default eventHandler(async (event) => {
  const sql = postgres(process.env.NUXT_DB_URL as string, {
    ssl: 'require'
  })
  const products = await sql`SELECT * FROM products`

  // Close the connection after the response
  event.waitUntil(sql.end())
  
  return products
})

atinux avatar Aug 26 '24 17:08 atinux

Postgres & Hyperdrive recipe is live: https://hub.nuxt.com/docs/recipes/postgres

atinux avatar Aug 27 '24 23:08 atinux