Is it possible to 'protect' a property and exclude it from select statements

is it possible synonym
is it possible to have
is it possible meaning
would it be possible
if it would be possible
would it be possible for you to meet
would it be possible sentences
is it possible to you

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.

This way only when it's explicitly requested in a select property, property2 statement.

I think a more accurate answer would be to set select: false on column options:

@Column({ select: false })
password: string;

And explicitly select the column like this:

const user = await getRepository(User)
    .createQueryBuilder()
    .addSelect('password')
    .getOne()

Why is "Is it possible to" a poorly worded question?, Yes or no? The simplest answer to an "is it possible to" question is "yes" or "no". Neither of these answers are really that good, helpful, or useful. Possible definition, that may or can be, exist, happen, be done, be used, etc.: a disease with no possible cure. See more.

TypeORM goes well with routing-controllers so you should use it, behind the scenes it uses class-transformer to serialize and deserialize your data. So you can use the @Exclude decorator from that library to prevent certain properties being sent down to the clients.

It also uses the class-validator library to validate the data when specifying it as the type in the controller functions. These are powerful toys. Here is a small example of how you can leverage both:

import { Entity, Column, PrimaryGeneratedColumn, Index, OneToMany } from "typeorm";
import { Exclude, Expose } from "class-transformer";
import { IsNotEmpty, IsEmail, MinLength, MaxLength, Min, Max, IsNumber, IsString } from "class-validator";

@Entity()
export class User extends BaseEntity {

  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  @IsNotEmpty()
  @IsEmail()
  @Index({ unique: true })
  email: string;

  @Exclude()
  @Column()
  passwordHash: string;

  @Column()
  @IsNotEmpty()
  @IsString()
  firstName: string;

  @Column()
  @IsNotEmpty()
  @IsString()
  lastName: string;

  @Column({ type: 'integer', default: Gender.NotSpecified })
  @IsNumber()
  @Min(1)
  @Max(3)
  gender: Gender;


  @Expose()
  get admin() {
    return this.role == Role.Admin;
  }

  @Expose()
  get stylist() {
    return this.role == Role.Stylist;
  }
}

If you use an another server-side library you can still take advantage of class-transformer and class-validator. You just need to call the validate function manually in your routes, for example for restify you can write:

import {validate } from "class-validator";
import {plainToClass} from "class-transformer";
// ... more code

server.post('/hello', function create(req, res, next) {
   let bodyJSON = parseBodyTheWayYouWant(req.body);
   let post = plainToClass(bodyJSON);
   validate(post)
   return next();
});

is it possible or is that possible?, is it possible vs is that possible. A complete search of the internet has found these results: is it possible is the most popular phrase on the web. Define possible. possible synonyms, possible pronunciation, possible translation, English dictionary definition of possible. adj. 1. Capable of happening, existing

You can use delete

Exemple Find All users

async findUsers(){
   const users:User[] = await userRepository.find();

    return users.map(user => { 
        delete user.password;
        delete user.salt;
        return user;
    }) ;
}

Exemple Find User By Id

async findUserById(id){
   const user:User = await userRepository.findOne(id);
   delete user.password;
   return user;
}

English Phrase: Would it be possible to (do something)?, This is a formal and polite way to ask for something: Would it be possible to make an appointment for later today? If you need to express who you're talking about,� Get in touch. Leave us some information and we'll get back to you. Your Name * Your company's name *

Here is solution - https://github.com/typeorm/typeorm/issues/535 The simplest solution is to exclude field(s) during query.

is it/would it be possible? synonyms with definition, Related terms for 'is it/would it be possible?': after you, any chance of?, any luck ?, any requests?, anyway, a penny for your thoughts. possible definition: 1. able to be done or achieved, or able to exist: 2. as much, quickly, soon, etc. as something can…. Learn more.

Which choice is grammatically correct “It is possible to not do this,” “It , The last one is, clearly, wrong; in no case would we ever say “It is possible to not to do this.” Why? Well, “to not” and “to do” are both infinitives. 10 synonyms of possible from the Merriam-Webster Thesaurus, plus 38 related words, definitions, and antonyms. Find another word for possible. Possible: capable of being done or carried out.

is it possible for you / is it possible that you, Is it possible you could send it back to me? Of course the simplest way would be to ask 'Could you" The thing is I have to use the word 'possible'� Synonyms for possible at Thesaurus.com with free online thesaurus, antonyms, and definitions. Find descriptive alternatives for possible.

"Is it possible you. ?" or "Is it possible if you , For the first option, you are wondering whether it is possible that you did something. For example, maybe you distinctly remember making a� possible - WordReference English dictionary, questions, discussion and forums. All Free.

Comments
  • This is the correct answer to the question. Here is a link to the docs: hidden-columns. Nonetheless the accepted answer is a valid solution.
  • This looks promising. But this is a non-documented feature right now, correct? At least not documented in TypeORM
  • I totally miss read your question. I have updated my answer to clarify this is the part or routing-conrollers which you really should use btw. Awesome product, and two goes well. (Take a look at typedi as well.)
  • Too bad I'm using restifyjs and not Koa or Expressjs
  • updated my answer with how to use it with different enviroments