Dr. Unstable
Dr. Unstable
CDCloudflare Developers
Created by Dr. Unstable on 10/6/2023 in #pages-help
How can I connect to a postgres database?
I'm trying to connect to my postgres database through node-postgres but it fails because of required node dependencies.
import { PRIVATE_DATABASE_URL } from '$env/static/private';
import pg from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
import * as schema from '$lib/schema/schema';
import * as relations from '$lib/schema/relations';

const connectionString = PRIVATE_DATABASE_URL;
const pool = new pg.Pool({
connectionString: encodeURI(connectionString),
});
const db = drizzle(pool, {
schema: { ...schema, ...relations},
});

export default db;
import { PRIVATE_DATABASE_URL } from '$env/static/private';
import pg from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
import * as schema from '$lib/schema/schema';
import * as relations from '$lib/schema/relations';

const connectionString = PRIVATE_DATABASE_URL;
const pool = new pg.Pool({
connectionString: encodeURI(connectionString),
});
const db = drizzle(pool, {
schema: { ...schema, ...relations},
});

export default db;
According to this https://orm.drizzle.team/docs/quick-postgresql/supabase#usage-with-cloudflare-workers. It should work in a worker. I'm just not sure why it's not working for my sveltekit pages deployment.
5 replies