hi, I’m trying to use the `upsert` method with a m...
# orm-help
a
hi, I’m trying to use the
upsert
method with a multi-column unique constraint, e.g.:
Copy code
// schema.prisma
model X {
  id        ...
  ...
  email     String
  subdomain String

  @@unique([email, subdomain])
}

// api
const upsertX = async params => {
  const { email, subdomain } = params;
  const upsertedX = await prisma.x.upsert({
    where: { email_subdomain: { email, subdomain } },
    update: { ... },
    create: { email, subdomain, ... },
  });
};
for some reason, the
upsert
call always runs for a long time and times out. I tried using
prisma.x.findMany({ where: { email, subdomain } })
instead and that seems to work fine… but shouldn’t the unique constraint make querying by
email_subdomain
faster (or at the very least, it shouldn’t time out). am I missing something?
r
I don't think you need to specify which indexes you're targetting, the db engine should be able to make that decision based on the query its given
a
I was following the examples here https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#examples-10, are you saying we don’t need to do that?
if I do
Copy code
await prisma.x.upsert({
  where: { email, subdomain },
  ...
)};
I get an error that
email
does not exist on
XWhereUniqueInput
r
I see, I wasn't aware of this, sorry for the confusion
a
any update on how to get this working?^
n
What’s your
@prisma/client
version?