TypeORM Basics — Series 2

Preview — 3 of 10 questions

What does this option do, and why must it stay off in production?

javascript
TypeOrmModule.forRoot({
  type: 'postgres',
  url: process.env.DATABASE_URL,
  entities: [Cat],
  synchronize: true,
});
AIt alters the database schema on every startup to match the entity definitions — convenient locally, but it can drop columns or tables whose entity definition changed, destroying data with no migration to review or roll back
BIt synchronises data between the primary database and its read replicas
CIt keeps entity instances in memory in sync with the database rows
DIt enables automatic retries for failed queries

Who sets these two values?

javascript
@Entity()
export class Cat {
  @PrimaryGeneratedColumn('uuid') id: string;
  @CreateDateColumn() createdAt: Date;
  @UpdateDateColumn() updatedAt: Date;
}
AThe application must assign them before calling save()
BA database trigger that TypeORM installs during the first migration
CTypeORM manages them automatically — createdAt is set on insert and updatedAt is refreshed on every update, with no application code involved
DThey are computed on read from the transaction log

What does each call do?

javascript
const cat = this.repo.create({ name: 'Bombay' });
await this.repo.save(cat);
Acreate() inserts the row and save() commits the surrounding transaction
BBoth write to the database; create() inserts and save() updates
Ccreate() validates the data against the entity's decorators and save() persists it
Dcreate() only builds an entity instance in memory — no SQL is issued — while save() is the call that inserts (or updates) the row

Sign up free to play

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