Skip to content

Instantly share code, notes, and snippets.

@hzburki
Created July 14, 2019 15:06
Show Gist options
  • Save hzburki/1520a98861bf699442909502dbc1ba15 to your computer and use it in GitHub Desktop.
Save hzburki/1520a98861bf699442909502dbc1ba15 to your computer and use it in GitHub Desktop.
User entity model - NestJS SequelizeJS Blog
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