PrismaP
Prisma9mo ago
2 replies
blackfish

Type safety with queries

Hi, I am using Primsa ORM, and I am having some problem with the type of the data returned from the query. For the types which can be a null value or string, it always returns as type string, but it can be null as well.

Here is my model:

model User {
  id                    String                @id
  accountPublicKey      String?               @map("account_public_key")
  isDeleted             Boolean               @default(false) @map("is_deleted")
  createdAt             Int                   @default(dbgenerated("(unixepoch('now') * 1000)")) @map("created_at")
  updatedAt             Int                   @default(dbgenerated("(unixepoch('now') * 1000)")) @map("updated_at")

  @@map("users")
}



Here accountPublicKey can be null.
but the query :
prisma.user.findUnique({
      select: {
        accountPublicKey: true,
        createdAt: true,
        id: true,
        isDeleted: true,
        updatedAt: true,
      },
      where: { id, isDeleted: false },
    });


this always returns accountPublicKey as string, even if its null.
Was this page helpful?