NeonN
Neon17mo ago
4 replies
incredible-moccasin

How to use the serverless driver for regular postgres (in node.js)?

I have a SvelteKit app, that uses the Vercel or Node adapter depending on an environment variable. For the Vercel build we use Neon, but for the Node build, we want to use local postgres.

Apparently I cannot do conditional paths in Sveltekit like the following cause the import itself causes the build to fail.

import { drizzle as drizzleNeon } from 'drizzle-orm/neon-http';
import { drizzle as drizzlePostgres } from 'drizzle-orm/postgres-js';

import postgres from 'postgres';
import { neon } from '@neondatabase/serverless';

import { sessionTable, userTable } from '../../schema';

import { DrizzlePostgreSQLAdapter } from '@lucia-auth/adapter-drizzle';

import { env } from '$env/dynamic/private';

const { PRIVATE_DRIZZLE_DATABASE_URL, PRIVATE_DRIZZLE_DATABASE_SERVERLESS } = env;

const sql =
  PRIVATE_DRIZZLE_DATABASE_SERVERLESS == 'false'
    ? postgres(PRIVATE_DRIZZLE_DATABASE_URL)
    : neon(PRIVATE_DRIZZLE_DATABASE_URL);

export const db =
  PRIVATE_DRIZZLE_DATABASE_SERVERLESS == 'false' ? drizzlePostgres(sql) : drizzleNeon(sql);

export const adapter = new DrizzlePostgreSQLAdapter(db, sessionTable, userTable);


So I am wondering if there is any way to use the Serverless driver for a Serverful postgres?
Was this page helpful?