Schema & Basic CRUD — Series 2

Preview — 3 of 10 questions

Which Prisma call correctly updates a single user's email by id?

javascript
await prisma.user.update({
  where: { id: 5 },
  data: { email: 'new@x.com' },
});
Aprisma.user.update({ where: { id: 5 }, data: { email: 'new@x.com' } })
Bprisma.user.update({ where: { active: true }, data: { email: 'new@x.com' } })
Cprisma.user.update({ data: { id: 5, email: 'new@x.com' } })
Dprisma.user.updateOne({ id: 5, email: 'new@x.com' })

Which Prisma call returns the number of active users, without fetching the actual rows?

javascript
const activeCount = await prisma.user.count({ where: { active: true } });
Aprisma.user.findMany({ where: { active: true } }).length
Bprisma.user.count({ where: { active: true } })
Cprisma.user.length({ where: { active: true } })
Dprisma.user.aggregate({ where: { active: true } }) returns a count by default with no configuration

What does createdAt DateTime @default(now()) do?

javascript
model Order {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}
AIt refreshes to the current time on every UPDATE, identical to @updatedAt
Bnow() is evaluated once when the schema is defined, giving every row the same fixed timestamp
CIt sets createdAt to the current timestamp automatically whenever a new row is INSERTed and no explicit value is provided — but unlike @updatedAt, it is not refreshed on subsequent updates
D@default(now()) requires the field type to be Int, storing a Unix timestamp

Sign up free to play

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