TypeORM là một trong những ORM phổ biến nhất với NestJS (Prisma cũng được ưa chuộng trong các project mới), sử dụng Data Mapper pattern thông qua Repository. Setup với TypeOrmModule.forRoot() trong AppModule cấu hình connection (type, host, port, credentials, entities path), synchronize: false trong production — dùng migrations thay.
Entity định nghĩa bằng @Entity() decorator với các column decorators: @PrimaryGeneratedColumn(), @Column(), @CreateDateColumn(), @UpdateDateColumn(). Relations: @OneToMany(), @ManyToOne(), @ManyToMany(), @OneToOne().
Trong feature module, TypeOrmModule.forFeature([Entity]) đăng ký Repository. Service inject @InjectRepository(Entity) để dùng Repository<Entity> với các methods: find(), findOne({ where: { id } }), create(), save(), update(), delete(). Lưu ý: TypeORM 0.3+ yêu cầu findOne() phải có { where: {...} }. Query Builder cho queries phức tạp: createQueryBuilder('alias').leftJoinAndSelect().where().getMany().