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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With