最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set a column with current time on Prisma? - Stack Overflow

programmeradmin2浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 6

Prisma 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

发布评论

评论列表(0)

  1. 暂无评论