Skip to content

Instantly share code, notes, and snippets.

@steebchen
Last active July 3, 2020 10:01
Show Gist options
  • Save steebchen/d1872fca96c93d97b717f4b11f6a2f5a to your computer and use it in GitHub Desktop.
Save steebchen/d1872fca96c93d97b717f4b11f6a2f5a to your computer and use it in GitHub Desktop.

example

const user = await prisma.user.update({
  where: {
    email: 'alice@prisma.io',
  },
  data: {
    posts: {
      update: [
        // a
        {
          data: { published: true },
          where: { id: 32 },
        },
        // b
        {
          data: { published: true },
          where: { id: 23 },
        },
      ],
    },
  },
})

with specific ("manually implemented") go client syntax:

result, err := client.User.FindOne(
  db.User.Email.Equals("alice@prisma.io"),
).Update(
  db.User.Posts.Update(
    // a
    User.Posts.FindOne(
      User.ID.Equals(32),
    ).Update(
      User.Published.Set(true),
    ),
    // b
    User.Posts.FindOne(
      User.ID.Equals(32),
    ).Update(
      User.Published.Set(true),
    ),
  ),
)

with inputTypes:

result, err := client.User.UpdateOne(
  db.UserWhereUniqueInput(
    db.UserWhereUniqueInputEmail("alice@prisma.io"),
  ),
  // data
  db.UserUpdateInput(
    // posts
    db.PostUpdateManyWithoutAuthorInput(
      // update (arr)
      // a
      db.PostUpdateWithWhereUniqueWithoutAuthorInput(
        db.UserUpdateWithWhereUniqueInput(
          db.PostWhereUniqueInput(
            db.PostWhereUniqueInputID(32),
          ),
          db.PostUpdateWithoutAuthorDataInput(
            db.PostUpdateWithoutAuthorDataInputPublished(true),
          ),
        ),
      ),
      // b
      db.PostUpdateWithWhereUniqueWithoutAuthorInput(
        db.UserUpdateWithWhereUniqueInput(
          db.PostWhereUniqueInput(
            db.PostWhereUniqueInputID(23),
          ),
          db.PostUpdateWithoutAuthorDataInput(
            db.PostUpdateWithoutAuthorDataInputPublished(true),
          ),
        ),
      ),
    ),
  ),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment