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

Support Cloudflare Hyperdrive connection in Nuxt-hub #208

Closed
wldbest opened this issue Jul 25, 2024 · 3 comments · Fixed by #245
Closed

Support Cloudflare Hyperdrive connection in Nuxt-hub #208

wldbest opened this issue Jul 25, 2024 · 3 comments · Fixed by #245
Labels
enhancement New feature or request

Comments

@wldbest
Copy link

wldbest commented Jul 25, 2024

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 wldbest changed the title Support Hyperdrive connection in Nuxt-hub Support Cloudflare Hyperdrive connection in Nuxt-hub Jul 25, 2024
@atinux atinux added the enhancement New feature or request label Aug 6, 2024
@atinux
Copy link
Contributor

atinux commented Aug 6, 2024

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

@atinux
Copy link
Contributor

atinux commented Aug 26, 2024

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
Copy link
Contributor

atinux commented Aug 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants