Neon errors

I cannot for the life of me create a hyperdrive connection to my Neon PG DB. It is always stuck in "inactive" and returns an error when attempting to use it "SERVER_ERROR: NeonDbError: Server error (HTTP status 530): error code: 1016" Is there some black magic I need to perform on the Neon side of things (because the hyperdrive side seems super simple)
9 Replies
AJR
AJR2w ago
Inactive just means it hasn't had any traffic in the last 24 hours. If it creates successfully that means it can connect, so it's not a permissions or connectivity issue. Can you paste some code snippets of how you're trying to use it in your Worker?
Kiwi
KiwiOP2w ago
Thanks for that. It's boilerplate stuff; the binding ("HYPERDRIVE", the ID, a localConnectionString) and then c.env.HYPERDRIVE.connectionString
import { drizzle as drizzlePostgres } from 'drizzle-orm/neon-http';
import { neon } from '@neondatabase/serverless';
import * as schema from './schema';

/**
* Create a drizzle client with the schema
* @param postgresUrl - The Postgres URL
* @returns The drizzle client
*/
export const getNeonPostgresDrizzleClient = (postgresUrl: string) => {
const sql = neon(postgresUrl);
return drizzlePostgres({ client: sql, schema, logger: true, casing: 'camelCase' });
};
import { drizzle as drizzlePostgres } from 'drizzle-orm/neon-http';
import { neon } from '@neondatabase/serverless';
import * as schema from './schema';

/**
* Create a drizzle client with the schema
* @param postgresUrl - The Postgres URL
* @returns The drizzle client
*/
export const getNeonPostgresDrizzleClient = (postgresUrl: string) => {
const sql = neon(postgresUrl);
return drizzlePostgres({ client: sql, schema, logger: true, casing: 'camelCase' });
};
AJR
AJR2w ago
Ah, I think I see the issue. We don't support Neon's driver. You'll need to swap it out for something like postgres.js or node-postgres Without going too far into the weeds, Neon's driver does a looot of custom stuff with the wire protocol.
Kiwi
KiwiOP2w ago
Aaaaaah. Thanks. I think I copy-pasta'd that from somewhere along the way, which is interesting.
Kiwi
KiwiOP2w ago
I think https://orm.drizzle.team/docs/connect-neon was my source for it
Drizzle ORM - Neon
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Kiwi
KiwiOP2w ago
Is there a recommended option between postgres.js or node-postgres for CF?
AJR
AJR2w ago
postgres.js is a bit slower but will be way friendlier for using on Workers and Pages due to being cleaner about how they use their node APIs and their imports. Generally that's what we recommend.
AJR
AJR2w ago
The snippet from here will give you the ideal connection settings for it, with Hyperdrive. https://developers.cloudflare.com/hyperdrive/get-started/
Cloudflare Docs
Getting started · Hyperdrive docs
Hyperdrive accelerates access to your existing databases from Cloudflare Workers, making even single-region databases feel globally distributed.
Kiwi
KiwiOP2w ago
Great, easy fix!
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import * as schema from './schema';

/**
* Create a drizzle client with the schema
* @param postgresUrl - The Postgres URL
* @returns The drizzle client
*/
export const getDrizzleClient = (postgresUrl: string) => {
const sql = postgres(postgresUrl);
return drizzle({ client: sql, schema, logger: true, casing: 'camelCase' });
};
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import * as schema from './schema';

/**
* Create a drizzle client with the schema
* @param postgresUrl - The Postgres URL
* @returns The drizzle client
*/
export const getDrizzleClient = (postgresUrl: string) => {
const sql = postgres(postgresUrl);
return drizzle({ client: sql, schema, logger: true, casing: 'camelCase' });
};

Did you find this page helpful?