quick help with select()

I'm sure there's something I can do about this, I'm just not sure. I've got a couple of tables, payments, bills etc. I want to select all of the columns from the payments table, plus billName from the bills table. When I try this
.select({
...schema.payments,
billName: schema.bills.billName,
})
.from(schema.payments)
.innerJoin(
schema.bills,
and(
eq(schema.bills.id, schema.payments.billId),
inArray(
schema.bills.householdId,
households.map((h) => h.households.id),
),
),
)
.select({
...schema.payments,
billName: schema.bills.billName,
})
.from(schema.payments)
.innerJoin(
schema.bills,
and(
eq(schema.bills.id, schema.payments.billId),
inArray(
schema.bills.householdId,
households.map((h) => h.households.id),
),
),
)
It works but I get the little Red Squiggles of Doom in my code editor. Surely there has to be a way to get this to work? (pic related)
No description
2 Replies
Sillvva
Sillvva3mo ago
Import getTableColumns from drizzle-orm
.select({
...getTableColumns(schema.payments),
billName: schema.bills.billName,
})
.select({
...getTableColumns(schema.payments),
billName: schema.bills.billName,
})
Mykhailo
Mykhailo3mo ago
Hey @jhechtf. Silva`s answer is what you need. Btw, you can follow this guide to read more about including/excluding columns https://orm.drizzle.team/learn/guides/include-or-exclude-columns
Drizzle ORM - Include or Exclude Columns in Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.