Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude certain fields from the selection using Drizzle ORM?

I’m using Drizzle ORM in my TypeScript project to work with a database, and I have a model representing user data that includes sensitive information like passwords. I want to exclude the ‘password’ field by default in all SELECT statements for security reasons.

like image 645
hantoren Avatar asked Oct 12 '25 16:10

hantoren


1 Answers

The easiest way to omit fields is with the getTableColumns() helper.

import { getTableColumns } from 'drizzle-orm';

const { password, ...nonPwCols } = getTableColumns(yourTable);
const result = await select(nonPwCols).from(yourTable);

See: Relevant part of the docs.

like image 177
rmarganti Avatar answered Oct 14 '25 06:10

rmarganti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!