Nicholas Ewing
09/09/2022, 12:51 PMMichael
09/09/2022, 2:26 PMnext(params)
in the transaction then create my log entry insert? Or is there another way to convert next(params)
to a proper query that prisma.$transaction()
can understand?dimidev
09/09/2022, 3:45 PMif (
e instanceof Prisma.PrismaClientKnownRequestError &&
e.code === 'P2002'
) {
throw new ConflictException("Email already used"));
} else {
throw new Error(e);
}
dimidev
09/09/2022, 3:47 PMInvalid `this.prisma.user.create()` invocation in
/root/Code/watergems-cloud/api/src/auth/auth.service.ts:51:43
48
49 try {
50 // ! SignUp can do only users
→ 51 const user = await this.prisma.user.create(
Unique constraint failed on the fields: (`email`)
dimidev
09/09/2022, 3:47 PMemail
)" without the traceback?Ofir Cohen
09/09/2022, 8:55 PMnpx prisma generate
to Git, or should I run this command as part of my prestart
step in npm
?
Context: I am deploying my web app in an air-gapped system and the npx prisma generate
tried to fetch some files from an online URL and failed miserably. Now I’m debating between:
1. Runing npx prisma generate
as part of the Docker build - to online fetch the auto-generated files
2. Checking-in the prisma client to GitHarris Rothaermel
09/09/2022, 11:20 PMmodel Conversation {
id String @id @default(uuid())
channelId String
active Boolean @default(true)
messages Message[]
participants User[]
summary String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([channelId, active], name: "active_conversation")
}
I was hoping to create a constraint that there is only ever 1 active (active = true) conversation in a channel, but I realized is that with the constraint as shown above, it actually prevents non-active conversations from being stored if there is already a non-active conversation in the same channelOfir Cohen
09/09/2022, 11:30 PMnpx prisma generate
on npm run dev
?Ofir Cohen
09/10/2022, 12:35 AMnpx prisma generate
as part of the Docker build step and have it cached as a side effect.David Wagner
09/10/2022, 12:33 PMPaulo Castellano
09/10/2022, 5:05 PMSlackbot
09/11/2022, 6:31 AMOmar
09/11/2022, 6:44 AMmodel Poll {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
text String
endsAt DateTime?
ownerToken String @db.VarChar(255)
options Option[]
}
model Option {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
text String
votes Int @default(0)
voterToken String @db.VarChar(255)
poll Poll @relation(fields: [pollId], references: [id])
pollId String
}
I'd like to be able to create a poll with the associated options to it but having a hard time maybe with my lack of understanding. How can I create the options mutation? where do I get the poll id from if we haven't created it yet and same goes for the voter token?
export const pollRouter = createRouter().mutation("create", { //>>>> is this validator right?
input: z.object({
text: z.string().min(5).max(600),
options: z
.array(z.object({ text: z.string().min(2).max(500) }))
.min(2)
.max(5),
endsAt: z.string(),
},
async resolve({ input, ctx }) {
if (!ctx.token) throw new Error("Unauthorized");
return await prisma.poll.create({
data: {
text: input.text,
ownerToken: ctx.token,
endsAt: input.endsAt,
options: { // I am stuck here on how to create the options
create: await prisma.option.create({
data: {
text: input.text,
voterToken: ctx.token,
poll:
}
})
},
},
include: {
options: true,
},
});
},
});
• Is my validation correct?
• Where do I get the pollId
that the options belong to?
• How do I get the mutation to go through if initially I don't have a voterToken
?Rexford Koomson
09/11/2022, 7:38 AMMinimal Sportswear
09/11/2022, 11:08 AMOmri Katz
09/11/2022, 11:55 AMOmri Katz
09/11/2022, 11:55 AMGal Elmalah
09/11/2022, 12:22 PMjuls07
09/12/2022, 5:28 AMAND
in a delete case?
trying to do something like
await prisma.like.delete({
where: {
AND: [
{
postId: postId
},
{
userId: ctx.user.userId
}
]
}
})
juls07
09/12/2022, 5:30 AMSimon Sardorf
09/12/2022, 9:56 AMawait prisma.cryptoaddress.update({
where: {
address: address,
},
data: {
balance: {
increment: parseFloat(amount),
},
},
});
Richard
09/12/2022, 11:00 AMMichael Roberts
09/12/2022, 11:54 AMconst transactionId = prisma.trasaction()
prisma.user.create()
try {
prisma.session.create()
} catch {
prisma.rollback(transactionId)
}
Mattèo Gauthier
09/12/2022, 11:54 AMAli
09/12/2022, 12:43 PMKelly Copley
09/12/2022, 1:45 PM'Error: Unique constraint failed on the (not available)',
Shaked Fried
09/12/2022, 2:00 PMKay Khan
09/12/2022, 2:16 PMError occurred during query execution:\nConnectorError(ConnectorError { user_facing_error: None, kind: RawDatabaseError { code: \"unknown\", message: \"Operation timed out (os error 110)\" } })
The mongodb official docs make mention of a socketTimeoutMS
https://www.mongodb.com/docs/v5.0/reference/connection-string/#mongodb-urioption-urioption.socketTimeoutMS but they say the default is to never timeout although it might vary depending on the driver. So im wondering if the underlining driver which prisma uses has this value set and if its possible to change.Geebrox
09/12/2022, 2:38 PMOR
filter? I have multiple docs where both OR
could return true. But I want to prioritize only one of them if both are true. e.g.: I have field isEmpty: boolean
and accountId: string?
I want to get where accountId
is defined and isEmpty
is false
or where accountId
is not defined and isEmpty
is true. In some cases both of them are true, and in such cases I want to get first conditions result. Please, adviceGeebrox
09/12/2022, 2:41 PMconst card = await this.prismaService.card.findFirst({
where: {
locale: account.locale,
OR: [
{ AND: [{ isEmptyCard: false }, { accountId: account.id }] },
{ isEmptyCard: true },
],
},
});
I use this code, and when both OR
conditions are true, it returns the result of the last one