codejump

Database Patterns

Preview — 3 of 10 questions

You want services to depend on a persistence abstraction, not TypeORM directly. What is the cleanest design in NestJS?

AInject Repository<Entity> everywhere and add if (driver === 'postgres') branches
BDefine a port interface (e.g. UserRepositoryPort) and bind it to a TypeORM adapter via a custom provider token; services depend only on the interface
CWrap every query in a stored procedure
DUse raw SQL strings centralized in one file

Which TypeORM construct best implements a Unit of Work so multiple repository operations commit atomically?

AA single dataSource.transaction(async (manager) => ...) where every operation uses that transactional EntityManager
BCalling save() on each repository separately and hoping they all succeed
CSetting synchronize: true
DWrapping calls in Promise.all

For strong data isolation between tenants with shared application code, which strategy gives the strongest isolation, and what is the tradeoff?

ARow-level (a tenantId column) — strongest isolation, lowest operational cost
BSchema-per-tenant (or database-per-tenant) — strongest isolation but higher migration/connection overhead vs. a shared schema with tenantId filtering
COne table per tenant in a shared schema — best for thousands of tenants
DStoring tenants as JSON blobs

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.