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")
}
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 },
});
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.
2 Replies
Prisma AI Help
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
Nurul
Nurul3w ago
Can you share the returned type you are getting?

Did you find this page helpful?