Creating Entities
import { Entity, Column, PrimaryKey, OneToMany } from 'vlodia';
@Entity({ tableName: 'users' })
export class User {
@PrimaryKey()
@Column({ type: 'number', generated: true })
id!: number;
@Column({ type: 'string', length: 100 })
name!: string;
@Column({ type: 'string', unique: true })
email!: string;
@Column({ type: 'string' })
password!: string;
@Column({ type: 'boolean', default: true })
active!: boolean;
@Column({ type: 'date', default: () => 'CURRENT_TIMESTAMP' })
createdAt!: Date;
@OneToMany(() => Post, 'authorId')
posts!: Post[];
}
Relations
// One-to-Many
@OneToMany(() => Post, 'authorId')
posts!: Post[];
// Many-to-One
@ManyToOne(() => User, 'posts')
author!: User;
// One-to-One
@OneToOne(() => Profile, 'userId')
profile!: Profile;
// Many-to-Many
@ManyToMany(() => Tag, 'user_tags')
tags!: Tag[];