Not able to connect my hyperdrive to my
Not able to connect my hyperdrive to my existing Neon DB with Drizzle ORM. WHY?
error when running
pnpm run dev
my wrangler.toml
[[hyperdrive]]
binding = "HYPERDRIVE"
id = "<ID>"
i got the ID by running npx wrangler hyperdrive create linkp-neon-hyperdrive --connection-string="
output:
š§ Creating 'linkp-neon-hyperdrive'
ā
Created new Hyperdrive config
{
"id": "<ID>",
"name": "linkp-neon-hyperdrive",
"origin": {
"host": "ep-old-sky--pooler.ap-southeast-1.aws.neon.tech",
"port": 5432,
"database": "linkp-db",
"scheme": "postgresql",
"user": "hyperdrive-user"
},
"caching": {
"disabled": false
}
}
Then in my src/index.ts
i have created a middlware to attach my DB instance in my requests:
export const injectDB = createMiddleware(async (c, next) => {
try {
console.log(
Connecting to database...${c.env.HYPERDRIVE.connectionString}
);
const sql = neon(c.env.HYPERDRIVE.connectionString);
c.req.db = drizzle({ client: sql, schema });
await next();
} catch (error) {
console.error("Database connection error:", error);
throw new HTTPException(503, { message: "Database connection failed" });
}
});
while drizzle is coming from import { drizzle } from "drizzle-orm/neon-http";
How can i solve this issue?
also tried using Postgres
& node-postgres
instead of neon-http
4 Replies
The error message screenshot that you shared was related to local development. Local development with
npx wrangler dev
will be using not the Hyperdrive configuration (in Cloudflare) but instead connect directly to a local database using the localConnectionString parameter. Full details in https://developers.cloudflare.com/hyperdrive/configuration/local-development/
If you want to use the 'remote' Hyperdrive configuration in Cloudflare, you can run npx wrangler dev --remote
getting some error while running this command
We're going to be removing that warning, but for now, if you add a localConnectionString in your wrangler.toml like this, when you run
npx wrangler dev --remote
, it will use the remote resource.thanks @thomasgauvin
will try it out
getting this error
Note: m using supabase client with remix