api-database-typeorm
Database with TypeORM
Quick Guide: Use TypeORM for decorator-based database access with full TypeScript support. Schema defined via entity classes with
@Entity,@Column,@PrimaryGeneratedColumn. Use Data Mapper pattern (repositories) over Active Record for non-trivial apps. Never usesynchronize: truein production - use migrations. Preferinsert()/update()oversave()when you know the operation type -save()always executes a SELECT first. UseQueryRunnertransactions for full control. Eager relations only work withfind*methods, not QueryBuilder.
<critical_requirements>
CRITICAL: Before Using This Skill
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST NEVER use synchronize: true in production - it can drop columns and lose data when entities change)
(You MUST use insert()/update() instead of save() when the operation type is known - save() always runs an extra SELECT query)
(You MUST use the provided transaction manager parameter or queryRunner.manager inside transactions - NEVER use the global entity manager or repository)
(You MUST define relations with explicit @JoinColumn() on the owning side of @OneToOne and optionally @ManyToOne, and @JoinTable() on one side of @ManyToMany)