CodePark/ questions / Repository, unit of work & data patterns
START PRACTICINGPRACTICE
Backend question · Software design & patterns › Repository, unit of work & data patterns

Which persistence pattern does this TypeORM code use?

@Entity()
class User extends BaseEntity {
  @PrimaryGeneratedColumn() id: number;
  @Column() email: string;
}
const user = User.create({ email: "a@b.com" });
await user.save();
const found = await User.findOneBy({ email: "a@b.com" });
Active Record

This is Active Record. The entity extends BaseEntity, and it saves and queries itself through its own instance and static methods.

It is not "Data Mapper". In TypeORM's Data Mapper style, the entity is a plain class. You save it through an injected repository or the entity manager, not through the entity itself.