Describe the Bug
After migrating from Vercel PostgreSQL to NeonDB, I updated my index.ts database configuration from:
import { sql } from '@vercel/postgres';
import { drizzle } from 'drizzle-orm/vercel-postgres';
import { config } from 'dotenv';
config({ path: '.env.local' });
export const db = drizzle(sql);
to
import { drizzle } from "drizzle-orm/neon-http";
import { neon } from "@neondatabase/serverless";
import { config } from "dotenv";
config({ path: '.env.local' });
const sql = neon(process.env.DATABASE_URL!);
export const db = drizzle(sql);
Since making this change, I’ve encountered a critical issue:
When storing an image buffer as a BYTEA type in the database, it appears to be saved correctly. However, upon retrieval, the image loses its format and is no longer recognized as a valid image, making it impossible to display.
Expected Behavior
When fetching the stored BYTEA image from the database, it should retain its original format and be properly renderable as an image.
Actual Behavior
After retrieving the stored BYTEA data, it does not retain its original image format and becomes unusable.
Steps to Reproduce
- Store an image as a
Bufferin aBYTEAcolumn in NeonDB. - Retrieve the stored image from the database.
- Attempt to display or process the image—it will not render correctly.
Potential Cause
This issue might be related to how NeonDB’s neon-http driver handles binary data compared to Vercel PostgreSQL’s @vercel/postgres driver. It’s possible that the binary encoding or decoding process is different, causing corruption when retrieving BYTEA data.
Environment
- Database: NeonDB
- ORM: Drizzle
- Node.js Version: v20.18.1
- Operating System: Win 11 & Ubuntu