#Bug in TypedSQL in version 5.22

8 messages · Page 1 of 1 (latest)

fossil schooner
#

Here is my schema
postgres latest

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["typedSql"]
}```
my chest Table
```ts
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

implemention

  try {
    const result = await db.$queryRawTyped(test());
    log.info({
      msg: 'result',
      result,
    });
  } catch (error) {
    log.error({
      msg: 'Error in test query',
      error,
    });
  }```
error 
```ts
ERROR: Error in test query
    error: {
      "clientVersion": "5.22.0"
    }```
error without a catch
```ts
"Cannot read properties of undefined (reading 'map')"```
hollow coyoteBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

fossil schooner
#

I think I found the root cause
if I remove extending replicas it works

const prisma = new PrismaClient().$extends(
  readReplicas({
    url: databaseUrlReplicas,
  }),
);```
#

okay I fixed it like this

 const result = await db.$replica().$queryRawTyped(test());```
fossil schooner
#

maybe worth adding as a warning in the documentation

sullen canopy
#

Hey @fossil schooner 👋
Thank you for reporting this.

If I understand correctly, this issue occurred as you were using read replicas with TypedSQL, right?

fossil schooner
#

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?