© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
11 replies
metowo

db.query returns empty object

I'm using commonjs for swapping out the query builder from knex and bookshelf with drizzle and am seeing that logging
db.query
db.query
returns an empty object which I found because
db.query.users.findFirst
db.query.users.findFirst
was giving me a can't call findfirst on undefined error.

this is my schema
const users = mySchema.table('users', {
  id: int('id').primaryKey().autoincrement(),
  username: varchar('username', { length: 100 }),
  password: varchar('password', { length: 100 }),
});
const users = mySchema.table('users', {
  id: int('id').primaryKey().autoincrement(),
  username: varchar('username', { length: 100 }),
  password: varchar('password', { length: 100 }),
});

and my db config
const connection = mysql.createConnection({
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  charset: 'utf8',
});

module.exports = connection
  .then(
    (conn) =>
      drizzle(conn, {
        schema,
        mode: 'default',
      })
  ).then((db) => console.log(db) || db); // logging here shows me that db.query is {}
const connection = mysql.createConnection({
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  charset: 'utf8',
});

module.exports = connection
  .then(
    (conn) =>
      drizzle(conn, {
        schema,
        mode: 'default',
      })
  ).then((db) => console.log(db) || db); // logging here shows me that db.query is {}
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

db.select() from magic sql`` operator returns array of empty objects
Drizzle TeamDTDrizzle Team / help
12mo ago
friendship query that returns the other user object
Drizzle TeamDTDrizzle Team / help
2y ago
query builder AND returns undefined
Drizzle TeamDTDrizzle Team / help
2y ago
rewrite with db.query
Drizzle TeamDTDrizzle Team / help
11mo ago