Get Schema From db instance

Hey! There's a way to get a table instance just from the 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
}


However, I'd like to make the table dyamic (it's a plugin) so we can't depend on the 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


Thanks in advance for your help!
Was this page helpful?