IsUniq validator
Custom validator for class-validator and typeorm
It validates uniqueness of any value across all records in a database. The validation can be narrowed down to a scope based on another column.
It doesn't consider nulls as unique values to be compatible with SQL specification
Installation
npm install @join-com/typeorm-class-validator-is-uniq --save
Usage
You can use the validator as any other class-validator
:
@Entity()
class User {
@PrimaryGeneratedColumn()
public id: string;
@IsUniq()
@Column()
public email: string;
@IsUniq({ scope: ['company'] })
@Column({ nullable: true })
public department: string;
@Column({ nullable: true })
public company: string;
}