Created
July 14, 2019 15:06
-
-
Save hzburki/1520a98861bf699442909502dbc1ba15 to your computer and use it in GitHub Desktop.
User entity model - NestJS SequelizeJS Blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
Table, | |
Column, | |
Model, | |
DataType, | |
CreatedAt, | |
UpdatedAt, | |
DeletedAt, | |
} from 'sequelize-typescript'; | |
import { IDefineOptions } from 'sequelize-typescript/lib/interfaces/IDefineOptions'; | |
const tableOptions: IDefineOptions = { | |
tableName: 'users', | |
} as IDefineOptions; | |
@Table(tableOptions) | |
export class User extends Model<User> { | |
@Column({ | |
type: DataType.BIGINT, | |
allowNull: false, | |
autoIncrement: true, | |
unique: true, | |
primaryKey: true, | |
}) | |
public id: number; | |
@Column({ | |
allowNull: false, | |
}) | |
name: string; | |
@Column({ | |
allowNull: false, | |
}) | |
age: number; | |
@Column({ | |
allowNull: false, | |
validate: { | |
isEmail: true, | |
}, | |
}) | |
email: string; | |
@CreatedAt public createdAt: Date; | |
@UpdatedAt public updatedAt: Date; | |
@DeletedAt public deletedAt: Date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment