eoin-obrien / prisma-extension-kysely

Drop down to raw SQL in Prisma without sacrificing type safety!
https://www.npmjs.com/package/prisma-extension-kysely
MIT License
189 stars 5 forks source link

Types Mismatch for postgres scalar lists #91

Open raaaaayn opened 4 months ago

raaaaayn commented 4 months ago

Describe the bug

nullable columns reported as non nullable

To Reproduce

clone this example repo and

Expected behavior

Expected Generated Types for scalar lists such as text[] integer[] json[] to be nullable

Model Definition

...

generator kysely {
  provider = "prisma-kysely"
}

...

model TestModel {
  id Int @id @default(autoincrement())

  list1 String[]
  list2 Int[]
  list3 Json[]
}

Postgres schema inspected after running prisma migrations

image

Versions:

Additional context

Noticed this bug when my website crashed in prod, I was able to reproduce this bug pretty easily and I don't think its a prisma/prisma-keysely version issue.

I have two api's that I'm calling which do almost the same query but one is through prisma the other one is through prisma-kysely

prisma.testModel.findFirst();
prisma.$kysely
    .selectFrom("TestModel")
    .selectAll()
    .limit(1)
    .execute();

and here's what the result looks like:

You can find the api endpoints at /api/test and /api/test-kysely in my example repo. please follow the setup instructions mentioned in the "To Reproduce" section.

If someone can point me in the right direction I will be more than happy to dig into this and hopefully create a PR to solve this in the near future

MrVhek commented 3 months ago

This is most probably a kysely and/or prisma issue. The way of handling types differ between prisma and kysely, which is why you may need to do some cast.