© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
14 replies
giovannibenussi

Get Schema From db instance

Hey! There's a way to get a table instance just from the
db
db
object?

Currently I have this:
await db.insert(users)...

And I want to provide a general function that performs an insert in a database:

function doSomething(db) {
  // insert a record in users table by default, but allow a different table name
}
function doSomething(db) {
  // insert a record in users table by default, but allow a different table name
}


However, I'd like to make the table dyamic (it's a plugin) so we can't depend on the
users
users
object to be available and I'd like to avoid asking users to provide it as a parameter. There's a way to make it work?

The table needs to follow a given schema (specified in our docs), so I wonder if it's possible to get the schema similar to this (just pseudo-code 😅):

db.nonexistingproperty.users // default
db.nonexistingproperty[userProvidedTableName] // override
db.nonexistingproperty.users // default
db.nonexistingproperty[userProvidedTableName] // override


Thanks in advance for your help!
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

Creating DB with schema
Drizzle TeamDTDrizzle Team / help
2y ago
Can't get relations from db.update
Drizzle TeamDTDrizzle Team / help
17mo ago
Get `CREATE TABLE ...` SQL from a schema
Drizzle TeamDTDrizzle Team / help
14mo ago
db.insert is not reading all properties from my schema
Drizzle TeamDTDrizzle Team / help
17mo ago