Created
August 1, 2021 06:31
-
-
Save Goldziher/1445dbb88060e42df457a5508689b87f to your computer and use it in GitHub Desktop.
Example TypeORM entities
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 { | |
Column, | |
CreateDateColumn, | |
Entity, | |
JoinColumn, | |
OneToOne, | |
PrimaryGeneratedColumn, | |
UpdateDateColumn, | |
} from 'typeorm'; | |
export abstract class AbstractUUIDPrimaryKeyEntity { | |
@PrimaryGeneratedColumn('uuid') | |
id: string; | |
@CreateDateColumn() | |
createdDate: Date; | |
@UpdateDateColumn() | |
updatedDate: Date; | |
} | |
@Entity() | |
export class UserProfile extends AbstractUUIDPrimaryKeyEntity { | |
@OneToOne(() => User) | |
user: User; | |
@Column('varchar') | |
location: string; | |
@Column('varchar') | |
employer: string; | |
@Column('varchar') | |
profession: string; | |
@Column('varchar') | |
phoneNumber: string; | |
@Column('varchar') | |
imageUrl: string; | |
@Column('date') | |
birthDate: Date; | |
} | |
@Entity() | |
export class User extends AbstractUUIDPrimaryKeyEntity { | |
@Column('varchar') | |
firstName: string; | |
@Column('varchar') | |
lastName: string; | |
@Column('varchar') | |
email: string; | |
@Column('boolean') | |
isActive: boolean; | |
@OneToOne(() => UserProfile, { cascade: true }) | |
@JoinColumn() | |
profile: UserProfile; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment