DT
Join ServerDrizzle Team
help
Select wildcard
I'm sure someone's asked this before but I can't find it.
Is there not a way to do a
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);
Found this thread, looks like no? https://discord.com/channels/1043890932593987624/1090954116152438814
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);
}
getTableColumns
will grab ... all table columns :pNice, thanks!