© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•10mo ago
mh

How to type a table with common column names ?

Hey, I have a couple tables that have some common column names, ex.
export const appointments = coreSchema.table(
    "appointments",
    {
        id: primaryKey(),
        accountId: foreignKey("account_id")
            .references(() => accounts.id)
            .notNull(),
        }
);

export const clients = coreSchema.table(
    "clients",
    {
        id: primaryKey(),
        accountId: foreignKey("account_id")
            .references(() => accounts.id)
            .notNull(),
        }
)
export const appointments = coreSchema.table(
    "appointments",
    {
        id: primaryKey(),
        accountId: foreignKey("account_id")
            .references(() => accounts.id)
            .notNull(),
        }
);

export const clients = coreSchema.table(
    "clients",
    {
        id: primaryKey(),
        accountId: foreignKey("account_id")
            .references(() => accounts.id)
            .notNull(),
        }
)


I want to be able to write a shared function that can be used to build queries with the account_id where condition already added to it, something like this

export const getQuery = (table: Table, accountId: string) => {
    const qb = new QueryBuilder();
    return qb.select().from(table).where(eq(table.accountId, accountId));
};
export const getQuery = (table: Table, accountId: string) => {
    const qb = new QueryBuilder();
    return qb.select().from(table).where(eq(table.accountId, accountId));
};


How should the type
Table
Table
be defined here? I've tried something like this
interface Table extends PgTable {
    accountId: PgColumn;
}
interface Table extends PgTable {
    accountId: PgColumn;
}


Is this a good/acceptable way to do it, or is there a more built-in drizzle type that can cover such scenarios?
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

How to get column names from Drizzle Table?
Drizzle TeamDTDrizzle Team / help
2y ago
How to type a function with column key of table
Drizzle TeamDTDrizzle Team / help
3y ago
How to type a Table
Drizzle TeamDTDrizzle Team / help
2y ago
Issue with truncating column names using `with`
Drizzle TeamDTDrizzle Team / help
2y ago