MinatoTW
MinatoTW
PPrisma
Created by MinatoTW on 1/19/2025 in #help-and-questions
Check array contains
Hello, what's the correct way to check if an array doesn't have a value? I'm doing this right now but it's not working:
await tx.player.update({
select: { id: true },
where: {
user_id: id,
level: { gte: trait.unlockLevel },
NOT: {
left_traits: { has: level },
right_traits: { has: level },
},
},
data: {
[`${side.toLowerCase()}_traits`]: { push: level },
},
});
await tx.player.update({
select: { id: true },
where: {
user_id: id,
level: { gte: trait.unlockLevel },
NOT: {
left_traits: { has: level },
right_traits: { has: level },
},
},
data: {
[`${side.toLowerCase()}_traits`]: { push: level },
},
});
Both are Int[] arrays and are empty right now, so this should work I think
2 replies
PPrisma
Created by MinatoTW on 12/31/2024 in #help-and-questions
Query Performance
Hello, I wonder if there's any way to disable the extra SELECT queries made during updates. For example: This is the query I'm using to update a player.
await tx.player.update({
where: { user_id: state.player1_id },
select: { id: true },
data: {
gold: { increment: player_gold },
platinum: { decrement: attemptCost },
potions: {
updateMany: usedPotions.map((potion) => ({
where: {
potion_id: potion.potion.id,
player_id: state.player1_id,
},
data: {
quantity: potion.quantity,
},
})),
},
},
});
await tx.player.update({
where: { user_id: state.player1_id },
select: { id: true },
data: {
gold: { increment: player_gold },
platinum: { decrement: attemptCost },
potions: {
updateMany: usedPotions.map((potion) => ({
where: {
potion_id: potion.potion.id,
player_id: state.player1_id,
},
data: {
quantity: potion.quantity,
},
})),
},
},
});
I see the following queries in the debug log:
api-1 | prisma:query UPDATE "public"."player_potions" SET "quantity" = $1 WHERE ("public"."player_potions"."id" IN ($2) AND 1=1)
api-1 | prisma:query SELECT "public"."player_potions"."id", "public"."player_potions"."player_id" FROM "public"."player_potions" WHERE (("public"."player_potions"."potion_id" = $1 AND "public"."player_potions"."player_id" = $2) AND "public"."player_potions"."player_id" IN ($3)) OFFSET $4
api-1 | prisma:query UPDATE "public"."player_potions" SET "quantity" = $1 WHERE ("public"."player_potions"."id" IN ($2) AND 1=1)
api-1 | prisma:query SELECT "public"."player_potions"."id", "public"."player_potions"."player_id" FROM "public"."player_potions" WHERE (("public"."player_potions"."potion_id" = $1 AND "public"."player_potions"."player_id" = $2) AND "public"."player_potions"."player_id" IN ($3)) OFFSET $4
api-1 | prisma:query UPDATE "public"."player_potions" SET "quantity" = $1 WHERE ("public"."player_potions"."id" IN ($2) AND 1=1)
api-1 | prisma:query UPDATE "public"."player_potions" SET "quantity" = $1 WHERE ("public"."player_potions"."id" IN ($2) AND 1=1)
api-1 | prisma:query SELECT "public"."player_potions"."id", "public"."player_potions"."player_id" FROM "public"."player_potions" WHERE (("public"."player_potions"."potion_id" = $1 AND "public"."player_potions"."player_id" = $2) AND "public"."player_potions"."player_id" IN ($3)) OFFSET $4
api-1 | prisma:query UPDATE "public"."player_potions" SET "quantity" = $1 WHERE ("public"."player_potions"."id" IN ($2) AND 1=1)
api-1 | prisma:query SELECT "public"."player_potions"."id", "public"."player_potions"."player_id" FROM "public"."player_potions" WHERE (("public"."player_potions"."potion_id" = $1 AND "public"."player_potions"."player_id" = $2) AND "public"."player_potions"."player_id" IN ($3)) OFFSET $4
api-1 | prisma:query UPDATE "public"."player_potions" SET "quantity" = $1 WHERE ("public"."player_potions"."id" IN ($2) AND 1=1)
Why is it making all those extra SELECT queries rather than just updating? I'm worried it might impact performance as we scale.
6 replies
PPrisma
Created by MinatoTW on 12/12/2024 in #help-and-questions
field reference help
hello I have models like this
model Player {
team Int[]
monsters Monster[]
}

model Monster {
id Int
name String
}
model Player {
team Int[]
monsters Monster[]
}

model Monster {
id Int
name String
}
how do I select player.monsters where id is in player.team[] I tried
monsters: { where: { id: { in: player.fields.team } } }
monsters: { where: { id: { in: player.fields.team } } }
but that's throwing type errors
6 replies