Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type error and remove unused import in Neon docs #490

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

andrelandgraf
Copy link

@andrelandgraf andrelandgraf commented Jan 31, 2025

This PR removes one unused import and attempts to fix a type error in the Neon docs.

Type error

On docs/get-started/neon-new page on Step 3 - Connect Drizzle ORM to the database.

If you need a synchronous connection, you can use our additional connection API, where you specify a driver connection and pass it to the Drizzle instance.

Code

import { neon } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-serverless';

const sql = neon(process.env.DATABASE_URL!);
const db = drizzle({ client: sql });

Type error for drizzle({ client: sql })

Argument of type '[{ client: NeonQueryFunction<false, false>; }]' is not assignable to parameter of type '[string | NeonClient] | [string | NeonClient, DrizzleConfig<Record<string, never>>] | [DrizzleConfig<Record<string, never>> & (({ ...; } | { ...; }) & { ...; })]'.
  Type '[{ client: NeonQueryFunction<false, false>; }]' is not assignable to type '[string | NeonClient] | [DrizzleConfig<Record<string, never>> & (({ connection: string | PoolConfig; } | { client: NeonClient; }) & { ...; })]'.
    Type '[{ client: NeonQueryFunction<false, false>; }]' is not assignable to type '[string | NeonClient]'.
      Object literal may only specify known properties, and 'client' does not exist in type 'NeonClient'.ts(2345)

Versions

  • @neondatabase/serverless: 0.10.4,
  • drizzle-orm: 0.39.1

Proposed solution

I think this code example is only meant to showcase passing the neon driver to Drizzle? In this case, I think we just need to update drizzle-orm/neon-serverless to drizzle-orm/neon-http for the default driver.

Not added in this PR, but if this example is meant to showcase the optional ws-based driver (which is brought up earlier on the same page), then I think more changes are needed:

// Use the Pool or Client constructors, instead of the functions described above, when you need:
// session or interactive transaction support, and/or compatibility with node-postgres
// See https://neon.tech/docs/serverless/serverless-driver#use-the-driver-over-websockets

import { drizzle } from 'drizzle-orm/neon-serverless';
import { Pool } from '@neondatabase/serverless';

const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const db = drizzle(pool);
// In environments where ws is not built in:
import { Pool, neonConfig } from '@neondatabase/serverless';
import ws from 'ws';

neonConfig.webSocketConstructor = ws;

@pffigueiredo
Copy link

LGTM! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants