Unable to use db.query... functions

Following is the documentation for performing queries: import * as schema from './schema'; import { drizzle } from 'drizzle-orm/...'; const db = drizzle({ schema }); The issue is that doesn't include any connection/credential information so it fails. It does see my schema information as evidenced by code completion but obviously won't work without connection info. If I define DB as this: import 'dotenv/config'; import { drizzle } from 'drizzle-orm/node-postgres'; // You can specify any property from the node-postgres connection options const db = drizzle({ connection: { connectionString: process.env.DATABASE_URL!, } }); It will connect successfully but I don't have any db.query...functions available (which is looking for a schema). I can db.select successfully. It seems it just doesn't see the schema. I'm not sure how to combine both of these into one db export. Ideally it would just reference what is already defined in the drizzle.config.ts file, but I don't know how to do that either.
2 Replies
scape
scape•3w ago
try doing this:
const db = drizzle(process.env.DATABASE_URL!, { schema })
const db = drizzle(process.env.DATABASE_URL!, { schema })
Baron_ThoughtEvolution
Baron_ThoughtEvolutionOP•3w ago
I must've tried everything under the sun but I shockingly never tried that. It works. Thanks very much. 🙂

Did you find this page helpful?