N
Neon13mo ago
adverse-sapphire

issue connecting neon with drizzle

Have the following in my index.ts file: const sql = neon(process.env.DATABASE_URL!); const db = drizzle({ client: sql }); Yet, seeing this error when I run the file: ➜ /workspaces/codespaces-blank/my-site(db_setup) $ npx tsx src/lib/server/db/index.ts Database URL:some-text-that-I-will-not-post-here /workspaces/codespaces-blank/my-site/node_modules/src/neon-serverless/session.ts:60 return client.query(rawQuery, params); ^ TypeError: client.query is not a function at NeonPreparedQuery.execute (/workspaces/codespaces-blank/my-site/node_modules/src/neon-serverless/session.ts:60:18) at <anonymous> (/workspaces/codespaces-blank/my-site/node_modules/src/pg-core/query-builders/insert.ts:332:27) at Object.startActiveSpan (/workspaces/codespaces-blank/my-site/node_modules/src/tracing.ts:27:11) at QueryPromise.execute (/workspaces/codespaces-blank/my-site/node_modules/src/pg-core/query-builders/insert.ts:331:17) at QueryPromise.then (/workspaces/codespaces-blank/my-site/node_modules/src/query-promise.ts:31:15) Node.js v20.17.0 Tried: "const db = drizzle(sql);" instead of drizzle({ client: sql }). It was also not working. Here is that error: TypeError: client.query is not a function at NeonPreparedQuery.execute (/workspaces/codespaces-blank/my-site/node_modules/src/neon-serverless/session.ts:60:18) at <anonymous> (/workspaces/codespaces-blank/my-site/node_modules/src/pg-core/query-builders/insert.ts:332:27) at Object.startActiveSpan (/workspaces/codespaces-blank/my-site/node_modules/src/tracing.ts:27:11) at QueryPromise.execute (/workspaces/codespaces-blank/my-site/node_modules/src/pg-core/query-builders/insert.ts:331:17) at QueryPromise.then (/workspaces/codespaces-blank/my-site/node_modules/src/query-promise.ts:31:15)
2 Replies
adverse-sapphire
adverse-sapphireOP13mo ago
Never mind, I fixed it. needed to use postgres instead of neon import postgres from 'postgres'; const sql = postgres(process.env.DATABASE_URL!, { ssl: { rejectUnauthorized: false }, // Necessary for Neon }); export const db = drizzle(sql); Now, I can populate the database.
evident-indigo
evident-indigo11mo ago
@sheabdu I just wrote a guide on how to use Drizzle with Local Postgres and Neon - https://neon.tech/guides/drizzle-local-vercel.
Neon
Drizzle with Local and Serverless Postgres - Neon Guides
A step-by-step guide to configure Drizzle ORM for local and serverless Postgres.

Did you find this page helpful?