drizzle-team/drizzle-orm · error · Error

Invalid arguments. Expected a connection string or a config

Error message

Invalid arguments. Expected a connection string or a config object.

What it means

An Error 'Invalid arguments. Expected a connection string or a config object.' thrown at the end of the netlify-db drizzle() factory (drizzle-orm/src/netlify-db/driver.ts:256). It is the terminal fallback after every recognised argument shape (zero-arg env-based, string connection string, isConfig object) has been tried. Reaching it means the arguments matched none of the overloads.

Source

Thrown at drizzle-orm/src/netlify-db/driver.ts:256

		if (client) {
			if ('driver' in client) {
				if (client.driver === 'serverless') {
					return construct(client.httpClient, client.pool, drizzleConfig);
				}
				return drizzleNodePg({ client: client.pool, ...drizzleConfig }) as any;
			}
			return construct(client.http, client.pool, drizzleConfig);
		}

		const connectionString = typeof connection === 'string' ? connection : connection!.connectionString;
		const httpClient = neon(connectionString);
		const pool = new Pool({ connectionString });

		return construct(httpClient, pool, drizzleConfig) as any;
	}

	throw new Error('Invalid arguments. Expected a connection string or a config object.');
}

export namespace drizzle {
	export function mock<
		TSchema extends Record<string, unknown> = Record<string, never>,
	>(
		config?: DrizzleConfig<TSchema>,
	): NetlifyDbDatabase<TSchema> & {
		$client: '$client is not available on drizzle.mock()';
	} {
		return construct({} as any, {} as any, config) as any;
	}
}

View on GitHub (pinned to b7862528fd)

Solutions

  1. Pass a connection string: drizzle(process.env.NETLIFY_DATABASE_URL!).
  2. Or pass a config: drizzle({ connection: process.env.NETLIFY_DATABASE_URL!, schema }).
  3. Or pass a DrizzleClient: drizzle({ client: { driver: 'serverless', httpClient, pool } }).
  4. If relying on zero-config, ensure you are on Netlify with the DB linked (no args) instead of passing a bad value.

Example fix

// before
import { drizzle } from 'drizzle-orm/netlify-db';
const db = drizzle(somePgPool); // not a recognised shape -> throws

// after
const db = drizzle(process.env.NETLIFY_DATABASE_URL!, { schema });
// or
const db = drizzle({ connection: process.env.NETLIFY_DATABASE_URL!, schema });
Defensive patterns

Strategy: validation

Validate before calling

function isValidNetlifyArgs(params: unknown[]): boolean {
  const [a] = params;
  if (params.length === 0) return true; // zero-config via env
  if (typeof a === 'string') return true;
  if (a && typeof a === 'object' && ('connection' in a || 'client' in a || 'schema' in a || 'casing' in a)) {
    return true;
  }
  return false;
}

if (!isValidNetlifyArgs(params)) {
  throw new Error('Pass a connection string or a config object to drizzle().');
}

Type guard

function isStringOrConfig(a: unknown): boolean {
  return typeof a === 'string' || (a !== null && typeof a === 'object');
}

Prevention

When it happens

Trigger: Calling drizzle() from drizzle-orm/netlify-db with an argument that is neither a string, a config object ( recognised by isConfig), nor empty. Examples: drizzle(123), drizzle(somePool) where the pool lacks the expected shape, drizzle(true), or a config object that does not pass isConfig.

Common situations: Passing a raw Postgres Pool/Client directly (netlify-db expects { client } or { connection } or a connection string), passing a non-string/non-object, or calling without NETLIFY_DATABASE_URL set in the zero-arg form on a non-Netlify host (getDatabase() would throw earlier, but malformed args reach this fallback).

Related errors


AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03). Data as JSON: /data/errors/bb3e70ef8e3a0665.json. Report an issue: GitHub.