Omit not working for me

I am trying to use Omit to return the object with the id field removed:
export type Item = InferSelectModel<typeof items>;
export type ReturnItem = Omit<Item, 'id'> & {};
export type Item = InferSelectModel<typeof items>;
export type ReturnItem = Omit<Item, 'id'> & {};
However when returned it still shows the id on the objects. I could add all the fields I want directly in the select() here but that seems like a lot of work.
export default async function getAllItems(
limit: number
): Promise<ReturnItem[]> {
const results = await queryDB.select().from(items).limit(limit);
return results;
}
export default async function getAllItems(
limit: number
): Promise<ReturnItem[]> {
const results = await queryDB.select().from(items).limit(limit);
return results;
}
3 Replies
Angelelz
Angelelz14mo ago
Omitting a field at the type level doesn't omit it in during runtime, you have to use javascript to omit it.
Angelelz
Angelelz14mo ago
I nice way to do this is as described here: https://orm.drizzle.team/docs/goodies#get-typed-table-columns
Goodies - DrizzleORM
Drizzle ORM | %s
Angelelz
Angelelz14mo ago
const { id, ...rest } = getTableColumns(items);
export default async function getAllItems(
limit: number
): Promise<ReturnItem[]> {
const results = await queryDB.select({ ...rest}).from(items).limit(limit);
return results;
}
const { id, ...rest } = getTableColumns(items);
export default async function getAllItems(
limit: number
): Promise<ReturnItem[]> {
const results = await queryDB.select({ ...rest}).from(items).limit(limit);
return results;
}
Want results from more Discord servers?
Add your server