All quizzesEasy
TypeORM Basics — Series 3
Preview — 3 of 10 questions
What is the practical difference?
javascript
@PrimaryGeneratedColumn('uuid') id: string; // (1)
@PrimaryGeneratedColumn() id: number; // (2)AForm (1) is faster to index because the values are shorter
BForm (2) is required whenever the table has relations
CForm (2) produces a sequential integer — compact and index-friendly, but it leaks how many rows exist and lets anyone guess neighbouring ids — while form (1) produces an unguessable identifier that can be generated by the application before the row is written, at the cost of a wider index
DForm (1) guarantees uniqueness only within one table, unlike form (2)
What does the argument do?
javascript
@Entity('cats')
export class Cat { /* ... */ }AIt sets the table name explicitly, instead of letting the naming strategy derive one from the class name
BIt names the entity for the repository token, without affecting the table
CIt creates a database schema called cats
DIt registers an alias used only in QueryBuilder expressions
What column does this create by default, and how would it become created_by_user_id?
javascript
@Column() createdByUserId: string;Acreated_by_user_id, since snake_case is TypeORM's default
BCREATEDBYUSERID, because identifiers are upper-cased
CIt cannot be changed without renaming the property
DcreatedByUserId by default — the property name is used verbatim — and a project-wide SnakeNamingStrategy (or an explicit @Column({ name: 'created_by_user_id' })) is what produces the snake_case form
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.