繁体   English   中英

Nestjs/Prisma 未正确保存日期编号

[英]Nestjs/Prisma not saving date number correctly

当我在将响应主体保存到数据库之前对其进行控制台记录时,我的响应主体形状看起来是正确的。 见下文


//console.log response body

CreateOpenHourDto {
day: 'WEDNESDAY',
startTime: 1663858800000,
endTime: 1663878600000,
calendarId: 1
}

但是,每当我 go 进入 prisma studio 并检查新的数据库条目时,startTime 和 endTime 都不同。

在此处输入图像描述

我没有做任何事情来转换数据。 任何提示表示赞赏。

我正在使用nestjs、prisma、postgres sql

我的 prisma model 将开始和结束时间列为“int”类型,它应该是 BigInt。 对于计划使用 bigint 的任何人。 意识到

Prisma returns records as plain JavaScript objects. If you attempt to use JSON.stringify on an object that includes a BigInt field, you will see the following error:

Do not know how to serialize a BigInt
To work around this issue, use a customized implementation of JSON.stringify:

JSON.stringify(
  this,
  (key, value) => (typeof value === 'bigint' ? value.toString() : value) // return everything else unchanged
)

这听起来很骇人听闻,但截至发表此评论时,它直接来自文档。

https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields#working-with-bigint

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM