Skip to content

Instantly share code, notes, and snippets.

@Goldziher
Created August 1, 2021 06:31
Show Gist options
  • Save Goldziher/1445dbb88060e42df457a5508689b87f to your computer and use it in GitHub Desktop.
Save Goldziher/1445dbb88060e42df457a5508689b87f to your computer and use it in GitHub Desktop.
Example TypeORM entities
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