@join-com/typeorm-class-validator-is-uniq
v2.0.0
Published
uniq validator for typeorm and class-validator
Downloads
146
Maintainers
Readme
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;
// Validates uniqueness of an email across all records
@IsUniq()
@Column()
public email: string;
// Validates uniqueness of a department in scope of a company
@IsUniq({ scope: ['company'] })
@Column({ nullable: true })
public department: string;
@Column({ nullable: true })
public company: string;
}