.upsert when no way to track query/track unique identifier?

I have a (plan to) setup where a user can like multiple posts. This can be done once per day.
model UserLikeStreaks {
id String @id @default(cuid())
serverID String
userID String
likeCount Int
likeTotal Int
createdAt DateTime @default(now())
recentLike DateTime @updatedAt
}
model UserLikeStreaks {
id String @id @default(cuid())
serverID String
userID String
likeCount Int
likeTotal Int
createdAt DateTime @default(now())
recentLike DateTime @updatedAt
}
Here is my structure, my logic being that I can query the where: { serverID, userID} and get the results of previous. Here's where I am misunderstanding, upsert only allows for one where entry? But I would need to query both in order to verify the correct entry.
ctx.prisma.userLikeStreaks.upsert({
where: {
serverID: input.server_id,
userID: ctx.session.id,

},
update: {
likeCount: {
increment: 1,
},
likeTotal: {
increment: 1,
},
},
create: {
serverID: input.server_id,
userID: ctx.session.id,
likeCount: 1,
likeTotal: 1,
},
}),
ctx.prisma.userLikeStreaks.upsert({
where: {
serverID: input.server_id,
userID: ctx.session.id,

},
update: {
likeCount: {
increment: 1,
},
likeTotal: {
increment: 1,
},
},
create: {
serverID: input.server_id,
userID: ctx.session.id,
likeCount: 1,
likeTotal: 1,
},
}),
This is the error I get inside VSCode:
Type '{ serverID: string; userID: string; }' is not assignable to type 'UserLikeStreaksWhereUniqueInput'.
Object literal may only specify known properties, and 'serverID' does not exist in type 'UserLikeStreaksWhereUniqueInput'.ts(2322)
Type '{ serverID: string; userID: string; }' is not assignable to type 'UserLikeStreaksWhereUniqueInput'.
Object literal may only specify known properties, and 'serverID' does not exist in type 'UserLikeStreaksWhereUniqueInput'.ts(2322)
3 Replies
Debaucus
Debaucus2y ago
The error when attempting to trigger the query:
Argument where of type UserLikeStreaksWhereUniqueInput needs exactly one argument, but you provided serverID and userID. Please choose one. Available args:
type UserLikeStreaksWhereUniqueInput {
id?: String
}
Unknown arg `serverID` in where.serverID for type UserLikeStreaksWhereUniqueInput. Did you mean `select`? Available args:
type UserLikeStreaksWhereUniqueInput {
id?: String
}
Unknown arg `userID` in where.userID for type UserLikeStreaksWhereUniqueInput. Did you mean `select`? Available args:
type UserLikeStreaksWhereUniqueInput {
id?: String
}
Argument where of type UserLikeStreaksWhereUniqueInput needs exactly one argument, but you provided serverID and userID. Please choose one. Available args:
type UserLikeStreaksWhereUniqueInput {
id?: String
}
Unknown arg `serverID` in where.serverID for type UserLikeStreaksWhereUniqueInput. Did you mean `select`? Available args:
type UserLikeStreaksWhereUniqueInput {
id?: String
}
Unknown arg `userID` in where.userID for type UserLikeStreaksWhereUniqueInput. Did you mean `select`? Available args:
type UserLikeStreaksWhereUniqueInput {
id?: String
}
I guess my question is 2 fold: 1) Can I use upsert/this design database? Or do I need to rethink my approach. 2) If I can make this work, what's the correct way to resolve this.
Kev
Kev2y ago
From what I understand, older versions of Prisma only expose unique fields (see the type UserWhereUniqueInput) on your models as fields in the where object when upsert is being used. According the docs: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#filter-on-non-unique-fields-with-userwhereuniqueinput, this behaviour was changed in Prisma >= 4.5.0 so you can reference non-unique fields in the where object.
Debaucus
Debaucus2y ago
Thank you!
Want results from more Discord servers?
Add your server