Select wildcard

I'm sure someone's asked this before but I can't find it. Is there not a way to do a .select() wildcard so that I can do something like:
db.select((defaultFields) => ({
max: sql<string>`MAX(${file.createdAt})`
...defaultFields
})).from(table);
db.select((defaultFields) => ({
max: sql<string>`MAX(${file.createdAt})`
...defaultFields
})).from(table);
3 Replies
rphlmr ⚡
rphlmr ⚡2y ago
I do things like this:
import { getTableColumns, sql, eq } from "drizzle-orm";

export async function getUser(id: string) {
return db
.select({
...getTableColumns(User),
fullName: sql<string>`${User.firstName} || ' ' || ${User.name}`,
})
.from(User)
.where(eq(User.id, id))
.then(takeFirstOrThrow);
}
import { getTableColumns, sql, eq } from "drizzle-orm";

export async function getUser(id: string) {
return db
.select({
...getTableColumns(User),
fullName: sql<string>`${User.firstName} || ' ' || ${User.name}`,
})
.from(User)
.where(eq(User.id, id))
.then(takeFirstOrThrow);
}
getTableColumns will grab ... all table columns :p
McLean 25
McLean 25OP2y ago
Nice, thanks!
Want results from more Discord servers?
Add your server