nuxt-hub / core

Build full-stack applications with Nuxt on CloudFlare, with zero configuration.
https://hub.nuxt.com
Apache License 2.0
992 stars 57 forks source link

Support Cloudflare Hyperdrive connection in Nuxt-hub #208

Closed wldbest closed 2 months ago

wldbest commented 3 months ago

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.

atinux commented 3 months ago

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

atinux commented 2 months ago

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 commented 2 months ago

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