Albert Montolio
08/11/2022, 8:32 PMdate
type using nestjs
app with prisma
and using postgresql
as db
. I opened this discussion on prisma’s github for further details on the question.
Basically I’m struggling to understand what date object
to pass to the this.prisma.user.create({ data: {date: XXX}})
. I define the field date
as DateTime @db.Date
in thet prisma schema.
But Postgresql
wants a date object with format 'YYYY-MM-DD',
but I’m in a nestjs
app, I can’t pass a string, since prisma is expecting a date object. If I do sth like new Date()
with whatever format, like iso and so on, it stills doesn’t correspond to the 'YYYY-MM-DD'
, I can only obtain this if I pass a string, but then prisma complains.
Could someone guide me on that topic? In the docu I just found this, but this just works purely with postgresql, not with the prisma client. Thanks!Nurul
08/16/2022, 9:02 AMYYYY-MM-DD
For now, you could use string datatype to store the date literal, or you could use this middleware which converts the date before sending the response to the client.Vladi Stevanovic