drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: Add `getTableName` options param to allow optionally prefixing table's schema name
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Describe what you want
While plugging some drizzle-defined tables with a third party library, I came across a situation where I had to pass the name of a few tables to non-drizzle functions for query building. In cases of cross-schema queries, this lead to some `relation not found` errors whenever table names were missing their schema. This can be easily solved in userland, but it seems just to think that the `getTableName` helper could add a few optional configs to handle it. Something like:
```ts
export function getTableName(
table: T,
{
withSchema = true,
quotes = true,
}: {
withSchema?: boolean;
quotes?: boolean;
} = {}
) {
const tableConfig = getTableConfig(table);
const q = quotes ? '"' : '';
return `${withSchema ? `${q}${tableConfig.schema}${q}.` : ''}${q}${tableConfig.name}${q}`;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.