DT
Drizzle Team5mo ago
H

How can we get all tables names

So i want to get all tables names i have in my schema.ts found this https://orm.drizzle.team/docs/goodies#get-table-information but it doesnt fit my use case
Drizzle ORM - Goodies
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
5 Replies
Quintisimo
Quintisimo5mo ago
This should work:
import * as schema from './schema';

const names = Object.keys(schema);

console.log(names);
import * as schema from './schema';

const names = Object.keys(schema);

console.log(names);
H
HOP5mo ago
thanks !
rphlmr ⚡
rphlmr ⚡5mo ago
If you have relations in your schema and want to filter them, you can Object.values(schema) and filter with is(table, PgTable) (or MySqlTable etc). Then get the keys like Quintisimo
H
HOP5mo ago
alright im gonna need that too thanks (for the context im currently building a tool to autogenerate database documentation and it will supports drizzle alongside with other ORM's)
rphlmr ⚡
rphlmr ⚡5mo ago
Nice! I am working in table and relation viewer! I can’t open source the code now but if you need to find something in particular, do not hesitate. I am working on cleaning my table parser today
Want results from more Discord servers?
Add your server