George / გიორგი
03/14/2021, 2:29 PMconst upsert = await prisma.analytics.upsert({
where: { date: new Date(body.date) },
update: {
viewers: body.viewers,
},
create: {
date: new Date(body.date),
country: body.country,
viewers: body.viewers,
}
})
res.status(204).json(upsert)
Sebastian Balay
03/14/2021, 7:59 PMcountry
to the where clause should do the trick:
const upsert = await prisma.analytics.upsert({
where: { date: new Date(body.date), country: body.country },
update: {
viewers: body.viewers,
},
create: {
date: new Date(body.date),
country: body.country,
viewers: body.viewers,
}
})
res.status(204).json(upsert)
George / გიორგი
03/15/2021, 8:46 AMSebastian Balay
03/15/2021, 8:55 AMdate
and country
in the where clause?George / გიორგი
03/15/2021, 9:01 AMSebastian Balay
03/15/2021, 9:58 AM@@unique([date, country])
and regenerate the types, you will get a new field that you can use in the where clause: date_country
Then you will be able to do:
const upsert = await prisma.analytics.upsert({
where: { date_country: { date: new Date(body.date), country: body.country } },
update: {
viewers: body.viewers,
},
create: {
date: new Date(body.date),
country: body.country,
viewers: body.viewers,
}
})
res.status(204).json(upsert)
George / გიორგი
03/15/2021, 10:35 AM