UNPKG

@wearesage/schema

Version:

A flexible schema definition and validation system for TypeScript with multi-database support

44 lines (35 loc) 729 B
import "reflect-metadata"; import { Entity, Id, Property, OneToMany, ManyToMany } from "../.."; import { Post } from "./Post"; @Entity() export class User { @Id() id: string; @Property({ required: true }) name: string; @Property({ required: true, unique: true }) email: string; // Timestamps @Property() createdAt: Date; @Property() updatedAt: Date; @ManyToMany({ target: () => User, inverse: "followers", name: "FOLLOWS", }) following: User[] = []; @ManyToMany({ target: () => User, inverse: "following", name: "FOLLOWS", }) followers: User[] = []; @OneToMany({ target: () => Post, inverse: "author", name: "AUTHORED", }) posts: Post[] = []; }