Hello folks, in Prisma 3.2.0, when I'm trying to u...
# orm-help
a
Hello folks, in Prisma 3.2.0, when I'm trying to update some object's
Json?
field (optional JSON), I can't use
undefined
because it then just treats it like there's no key, and I can't use
null
because then Prisma is angry with me. Can someone please help me update an object in such way? It's not a key within the JSON, but literally I want to update a previously updated JSON (say
{"a": "b"}
) to NULL
r
You can use null as that's a perfectly valid value. Could you share your schema and query that you're making?
a
Ha, it screams at me. I'll paste some more info in here in a few hours. Basically, trying to do:
Copy code
prisma.something.update({
  where: ...
  data: {
    jsonField: null
  }
}
The type is not accepted there, it was on 2.24. I'll investigate more anyway and will update in here, thanks a lot for the quick response
r
Is the Json field nullable?
a
Yes sir, it works fine in 2.24.1
r
Could you share a basic reproduction? I would like to try this out.
a
Yeah I will paste something in here
In the meantime I managed to solve it with assigning
Prisma.DbNulll
as the value
Instead of
null
, e.g.:
Copy code
if (somethingRemoved) {
  await prisma.obj.update({
    where: id.
    data: {
      jsonColumn: Prisma.DbNull
    }
  })
}
Does that makes sense at all? The generated typescript (
index.d.ts
) type is:
Copy code
export type MyObject = {
  ...
  jsonColumn?: NullableJsonNullValueInput | InputJsonValue
  ...
}
a
Thanks, I saw that but I thought it applies only to filtering
Is it also for
UPDATE
statements?
(this section in the doc is why I have attempted using
DbNull
)
r
Yes it should be for updates as well.
a
So that was the problem. Thanks a lot!
💯 1