admin管理员组文章数量:1356084
I'm making a node api using prisma ORM and i'm trying to update a column which i had set with the type DateTime, here is the model, the column is the deleted_at one
model Employee {
id Int @id @default(autoincrement())
name String
created_at DateTime
deleted_at DateTime
}
how can i change it to the current time in my controller? the controller looks like this
export const DeleteCompany = async (req:IEmployee, res:Response) => {
const data:ICompany = req
const deletedCompany = await prisma.employee.update({
where: {
id: Number(data.id)
},
data: {
deleted_at: //what should I put here?
}
})
return res.status(200).json(deletedCompany)
}
I've tried using
now()
but it didnt work.
I'm making a node api using prisma ORM and i'm trying to update a column which i had set with the type DateTime, here is the model, the column is the deleted_at one
model Employee {
id Int @id @default(autoincrement())
name String
created_at DateTime
deleted_at DateTime
}
how can i change it to the current time in my controller? the controller looks like this
export const DeleteCompany = async (req:IEmployee, res:Response) => {
const data:ICompany = req
const deletedCompany = await prisma.employee.update({
where: {
id: Number(data.id)
},
data: {
deleted_at: //what should I put here?
}
})
return res.status(200).json(deletedCompany)
}
I've tried using
now()
but it didnt work.
Share Improve this question asked Feb 2, 2023 at 21:08 Hermes SantosHermes Santos 411 silver badge4 bronze badges2 Answers
Reset to default 6Prisma supports plain javascript dates for setting date fields.
So new Date()
should work fine:
deleted_at: new Date()
To create a current datetime field using prisma model enter this in the field
model Employee {
id Int @id @default(autoincrement())
name String
created_at DateTime @default(now())
deleted_at DateTime @default(now())
}
Using the type DateTime
and adding @default(now())
will generate the current DAte and time to the field
本文标签: javascriptHow to set a column with current time on PrismaStack Overflow
版权声明:本文标题:javascript - How to set a column with current time on Prisma? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743975541a2570862.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论