specs icon indicating copy to clipboard operation
specs copied to clipboard

Prisma Client JS: Shortcut syntax for @id / @@id

Open schickling opened this issue 5 years ago • 0 comments

This Prisma Client JS change introduces an API shortcut syntax when referencing single-field @id fields and multi-field @@id fields.

// before
const user = await prisma.user.findOne({ where: { id: 42 } })
const newPost = await prisma.post.create({
  data: {
    title: 'Hello',
    author: { connect: { id: 42 } },
  },
})

// after (before still works)
const user = await prisma.user.findOne({ where:  42 })
const newPost = await prisma.post.create({
  data: {
    title: 'Hello',
    author: { connect: 42 },
  },
})

This applies to:

  • findOne({ where: ... })
  • Nested write operations with { connect: ... }
  • Pagination

schickling avatar Mar 06 '20 15:03 schickling