How to update and upsert on particular columns on Prisma

On Prisma, I have a session model as follows
export type sessionsCreateInput = {
id?: bigint | number
hash: string
user_id: bigint | number
}
export type sessionsCreateInput = {
id?: bigint | number
hash: string
user_id: bigint | number
}
this is accepted with no type issues:
await prisma.sessions.create({
data: {
hash,
user_id: id,
},
});
}
await prisma.sessions.create({
data: {
hash,
user_id: id,
},
});
}
however, when updating or upserting as follows, I get yelled at for type issues:
await prisma.sessions.update/upsert({
where: {
user_id: id, // <---- linter yells here
},
data: {
hash,
},
});
await prisma.sessions.update/upsert({
where: {
user_id: id, // <---- linter yells here
},
data: {
hash,
},
});
the error I get is: Type '{ user_id: bigint; }' is not assignable to type 'sessionsWhereUniqueInput'. Object literal may only specify known properties, and 'user_id' does not exist in type 'sessionsWhereUniqueInput'.ts(2322) index.d.ts(6213, 5): The expected type comes from property 'where' which is declared here on type '{ select?: sessionsSelect | null | undefined; data: (Without<sessionsUpdateInput, sessionsUncheckedUpdateInput> & sessionsUncheckedUpdateInput) | (Without<...> & sessionsUpdateInput); where: sessionsWhereUniqueInput; }' how can I fix this?
2 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
alan
alan3y ago
thank you! I went ahead and did that and it fixed the problem
Want results from more Discord servers?
Add your server