drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.61k stars 649 forks source link

[BUG]: Drizzle ORM does not throw error when PostgreSQL server is unreachable #3572

Open ASgmbv opened 5 days ago

ASgmbv commented 5 days ago

Report hasn't been filed before.

What version of drizzle-orm are you using?

0.36.3

What version of drizzle-kit are you using?

0.28.1

Other packages

No response

Describe the Bug

When attempting to connect to a PostgreSQL database that is not running, Drizzle ORM does not throw an error as expected. This silent failure makes it difficult to implement proper error handling and could lead to unexpected behavior in production environments.

Current Behavior

Expected Behavior

Steps to Reproduce

import { FastifyInstance } from "fastify";
import { drizzle, NodePgDatabase } from "drizzle-orm/node-postgres";
import * as schema from "../db/schema";
import fp from "fastify-plugin";

export type db = NodePgDatabase<typeof schema>;

// TODO: not throwing error when postgres is not running
async function db(app: FastifyInstance) {
  const db = drizzle(app.config.DATABASE_URL, {
    schema: schema,
  });

  app.decorate("db", db);
}

export default fp(db);