Bug in TypedSQL in version 5.22

Here is my schema postgres latest
generator client {
provider = "prisma-client-js"
previewFeatures = ["typedSql"]
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["typedSql"]
}
my chest Table
model Chest {
id String @id @default(cuid()) @map("id")
name String @map("name")
imageUrl String? @map("image_url")
description String? @map("description")
rarity Rarity @map("rarity")
amount Int? @map("amount")
gameId String @map("game_id")
game Game @relation(fields: [gameId], references: [id], onDelete: Cascade)
currencies ChestCurrency[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@unique([gameId, rarity])
@@index([gameId])
@@map("chests")
}
model Chest {
id String @id @default(cuid()) @map("id")
name String @map("name")
imageUrl String? @map("image_url")
description String? @map("description")
rarity Rarity @map("rarity")
amount Int? @map("amount")
gameId String @map("game_id")
game Game @relation(fields: [gameId], references: [id], onDelete: Cascade)
currencies ChestCurrency[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@unique([gameId, rarity])
@@index([gameId])
@@map("chests")
}
my test query inside prisma/sql
-- @name test
SELECT *
FROM chests
-- @name test
SELECT *
FROM chests
implemention
try {
const result = await db.$queryRawTyped(test());
log.info({
msg: 'result',
result,
});
} catch (error) {
log.error({
msg: 'Error in test query',
error,
});
}
try {
const result = await db.$queryRawTyped(test());
log.info({
msg: 'result',
result,
});
} catch (error) {
log.error({
msg: 'Error in test query',
error,
});
}
error
ERROR: Error in test query
error: {
"clientVersion": "5.22.0"
}
ERROR: Error in test query
error: {
"clientVersion": "5.22.0"
}
error without a catch
"Cannot read properties of undefined (reading 'map')"
"Cannot read properties of undefined (reading 'map')"
3 Replies
Mohammad Orabi 🇱🇧
I think I found the root cause if I remove extending replicas it works
const prisma = new PrismaClient().$extends(
readReplicas({
url: databaseUrlReplicas,
}),
);
const prisma = new PrismaClient().$extends(
readReplicas({
url: databaseUrlReplicas,
}),
);
okay I fixed it like this
const result = await db.$replica().$queryRawTyped(test());
const result = await db.$replica().$queryRawTyped(test());
maybe worth adding as a warning in the documentation
Nurul
Nurul•2w ago
Hey @Mohammad Orabi 🇱🇧 👋 Thank you for reporting this. If I understand correctly, this issue occurred as you were using read replicas with TypedSQL, right?
Mohammad Orabi 🇱🇧
yes but I fixed it and it worked correctly with explicitly stating if primary or replica and if you responded , I have another issue that I was not able to fix which is different than this but also TypedSql related , may I share it , or do a new thread? will do a new one
Want results from more Discord servers?
Add your server