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:
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 😅):
Thanks in advance for your help!5 Replies
following this
Your question is ambiguous.
What does it mean for a table to be "dynamic"
Or do you mean that which table is being inserted to (i.e. the table name) is dynamic?
i think the goal is to achieve something like this
ive messed around with many things, such as
unfortunately i havent been able to write an interface for that function that actually types out correctly
or, an even simpler example, achieving something like this
unfortunately, what
_.schema
has is not the same thing as the actual schema youre supposed to use inside .from()
quick update, the
select
interface holds no type information regarding the schema given at db initializationthis basically means you can pass whatever you want to it as long as its an actual table, it doesnt restrict possible tables based on the schema
i guess whats left is to figure out if the previous desired behavior is at least achievable using the
query
api
this was probably my best attempt, unfortunately findMany
errors with This expression is not callable