是否可以“保护"属性并将其从选择语句中排除 [英] Is it possible to 'protect' a property and exclude it from select statements
本文介绍了是否可以“保护"属性并将其从选择语句中排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在数据层级别保护某些属性.例如,我想保护我为用户存储在数据库中的密码哈希,以便它不会出现在任意 select
语句中.
I'd like to protect certain properties on the data-layer level. For example I'd like to protect the password hash I store in the database for a user, so that it doesn't show up in arbitrary select
-statements.
仅当在 select property, property2
语句中明确请求时才采用这种方式.
This way only when it's explicitly requested in a select property, property2
statement.
推荐答案
我认为更准确的答案是在列选项上设置 select: false
:
I think a more accurate answer would be to set select: false
on column options:
@Column({ select: false })
password: string;
并像这样明确选择列:
const user = await getRepository(User)
.createQueryBuilder()
.addSelect('password')
.getOne()
这篇关于是否可以“保护"属性并将其从选择语句中排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文