Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

create OR connect on nested writes (upsert) #336

Closed
johanmic opened this issue Oct 18, 2019 · 12 comments
Closed

create OR connect on nested writes (upsert) #336

johanmic opened this issue Oct 18, 2019 · 12 comments
Assignees
Labels
Milestone

Comments

@johanmic
Copy link

is there a plan to add an upsert to nested writes? The use case is when you dont know if the nested record exists or not

say im creating a movie with a list of n actors, some already exist and some do not.
using either create or connect wont work since i dont know beforehand which exist or not.

the only current solution is to loop and upsert the entire list and then always use connect.
so instead of connect, create also add an upsert

(pseudo ish)

const actors = [{name:'Johnny Dopp'}, {name:'Brad Pitts'}]

const actorIds = Promise.all(actors.map((actor)=>photon.artists.upsert({
    where: { name: actor.name },
    update: {},
    create: actor
  }))

photon.movie.create({
    name: "something",
    cast: {
      connect: actorIds.map(actor=>actor.id)
    }
  })

but instead

photon.movie.create({
    name: "something",
    cast: {
      upsert: [ 
          {name:'Johnny Dopp'}, 
          {name:'Brad Pitts'}
      ]
    }
  })

the first one is not very ACID obviously.

@pantharshit00
Copy link
Contributor

You can open an issue about this in the specs repo so that we can include it in the upcoming photonjs API changes: https://github.com/prisma/specs

Also, checkout photonjs spec: https://github.com/prisma/specs/tree/master/photonjs

@janpio janpio transferred this issue from prisma/prisma Dec 13, 2019
@janpio janpio added the kind/feature A request for a new feature. label Dec 13, 2019
@mavilein
Copy link
Member

Internal Note: We do have nested upsert but we only expose it within an update. Exposing this might be very simple. It is mostly writing a few test cases i assume.

@janpio janpio added the process/candidate Candidate for next Milestone. label Feb 19, 2020
@divyenduz divyenduz added process/candidate Candidate for next Milestone. and removed process/candidate Candidate for next Milestone. labels Mar 3, 2020
@johanmic
Copy link
Author

johanmic commented Mar 4, 2020

Any plans to implement this? @mavilein
it would be an amazing feature

@mavilein
Copy link
Member

mavilein commented Mar 20, 2020

Just realized that we already have a more prominent issue for this feature request: prisma/prisma1#2194

@janpio janpio reopened this Mar 20, 2020
@janpio
Copy link
Member

janpio commented Mar 20, 2020

That one is for Prisma1 though, which we do not look into around here ;)

@johanmic
Copy link
Author

so a feature thats been requested since 2018 and might be very simple. sounds like a good candidate @mavilein :)

@ssalbdivad
Copy link

@jaywalklabs @mavilein @janpio Agree, this would remove a lot of boilerplate!

@johanmic
Copy link
Author

@ssalbdivad not no mention actually support transactions which the boilerplate workaround does not.

@ManAnRuck
Copy link

this would be awesome when it works! 🤗

@albertoperdomo albertoperdomo added the process/candidate Candidate for next Milestone. label May 19, 2020
@albertoperdomo albertoperdomo self-assigned this May 19, 2020
@albertoperdomo albertoperdomo added team/product tech/engines Issue for tech Engines. labels May 19, 2020
@janpio janpio added this to the Beta 7 milestone May 26, 2020
@janpio janpio removed process/candidate Candidate for next Milestone. team/product labels May 26, 2020
@janpio janpio modified the milestones: Beta 7, Beta 8 May 29, 2020
@janpio janpio added the process/candidate Candidate for next Milestone. label Jun 10, 2020
@janpio janpio modified the milestones: Beta 10, 2.1.0 Jun 10, 2020
@dpetrick
Copy link

The connectOrCreate nested operation is available on dev and will land on stable with the next release (2.1.0).

@RoaldSchuring

This comment has been minimized.

@janpio
Copy link
Member

janpio commented Jul 4, 2020

Moved into separate issue #764 @RoaldSchuring

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

10 participants