Bird
0
0

Given this entity code snippet, what will be the database column type for createdAt?

medium📝 component behavior Q4 of 15
NestJS - Database with TypeORM
Given this entity code snippet, what will be the database column type for createdAt?
@Entity()
export class Post {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'timestamp' })
  createdAt: Date;
}
AA string column storing date as text
BA boolean column indicating creation status
CAn integer column storing Unix timestamp
DA timestamp column storing date and time
Step-by-Step Solution
Solution:
  1. Step 1: Check the @Column decorator options

    The type: 'timestamp' option specifies the database column type as timestamp.
  2. Step 2: Understand how Date maps to database types

    In TypeORM, a Date property with type 'timestamp' stores date and time values in the database.
  3. Final Answer:

    A timestamp column storing date and time -> Option D
  4. Quick Check:

    Timestamp column type [OK]
Quick Trick: Use type: 'timestamp' for date-time columns [OK]
Common Mistakes:
  • Assuming Date maps to string automatically
  • Confusing timestamp with integer Unix time
  • Ignoring the type option in @Column

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes