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

"Error connecting to database: fetch failed" using drizzle and SST #5362

Open
nvsd opened this issue Sep 23, 2023 · 6 comments
Open

"Error connecting to database: fetch failed" using drizzle and SST #5362

nvsd opened this issue Sep 23, 2023 · 6 comments
Labels
t/bug Issue Type: Bug

Comments

@nvsd
Copy link

nvsd commented Sep 23, 2023

Steps to reproduce

use neon with drizzle and attempt to connect to neon from an SST function

import { neon, neonConfig } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";

neonConfig.fetchConnectionCache = true;

const sql = neon(process.env.DATABASE_URL!);
export const db = drizzle(sql);

// in SST function
export const get = ApiHandler(async (_evt) => {
  const data = await db.select().from(someTable).execute();
  const body = JSON.stringify(data);

  return ok(body);
});

Expected result

Able to query data from neon database over http

Actual result

serverless function times out

Environment

serverless?

Logs, links

Error: Error connecting to database: fetch failed
       at execute (/Users/zack/Projects/api/node_modules/.pnpm/@[email protected]/node_modules/@neondatabase/serverless/index.js:1533:49)
       at NeonHttpPreparedQuery.execute (/Users/zack/Projects/api/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_37yoyvqj3lzqjkmyukc4pac6mi/node_modules/src/neon-http/session.ts:57:18)
       at <anonymous> (/Users/zack/Projects/api/packages/functions/src/exercises.ts:8:33)
       at <anonymous> (/Users/zack/Projects/api/node_modules/.pnpm/[email protected]/node_modules/sst/node/api/index.js:28:22)
       at async file:///Users/zack/Projects/api/node_modules/.pnpm/[email protected]/node_modules/sst/support/nodejs-runtime/index.mjs:148:16
@nvsd nvsd added the t/bug Issue Type: Bug label Sep 23, 2023
@nvsd
Copy link
Author

nvsd commented Sep 23, 2023

I might be using the wrong URL for serverless HTTP?
The one I'm using is postgres://<username>:<password@<URI>/<db>

@kam-st
Copy link

kam-st commented Jun 9, 2024

Were you able to resolve this? The direct connection via npx drizzle-kit push works. But have same issue.

It is not the issue with url, as this postgres url works with other drivers.

@yita0101
Copy link

neon.tech use this server.you will get a connect link like

@yita0101
Copy link

image

@GokulDas027
Copy link

This is probably caused by your network/dns.
I had this Error during migration: NeonDbError: Error connecting to database: fetch failed during migrations, and was fixed using cloudflare warp.

@cliffordkleinsr
Copy link

See here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/bug Issue Type: Bug
Projects
None yet
Development

No branches or pull requests

5 participants