【问题标题】:How to select items in prisma with date GTE > current date如何使用日期GET>当前日期选择prisma中的项目
【发布时间】:2022-11-07 21:32:19
【问题描述】:

嗨,我是新来的 prisma,并试图在 prisma 中选择未来的日期,而不是抓住任何“过期”的日子。

我在docs 中看到有一个prisma.now(),但是当我注销cosole.log(prisma) 时在控制台中看不到它

有没有人知道一个好的解决方案?

我的created_at 采用这种格式:2022-01-13 12:00

app.get("/ques", async function (req, res) {
  console.log("PRISMA", prisma.NOW());
  const allQues = await prisma.que.findMany({
    where: {
      created_at: {
        gte: prisma.NOW(),
      },
    },
  });
  res.status(200).send(allQues);
});

【问题讨论】:

    标签: node.js prisma


    【解决方案1】:

    我不确定这样的事情是否存在? (prisma.NOW())

    now() 只是您可以在架构文件中使用来设置默认值的函数,例如:

    model User {
      registeredAt     DateTime @default(now())
    }
    

    在您的应用代码中,您可以只使用常规的 Javascript Date 对象,例如:

      const allQues = await prisma.que.findMany({
        where: {
          created_at: {
            // new Date() creates date with current time and day and etc.
            gte: new Date()
          },
        },
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-22
      • 1970-01-01
      相关资源
      最近更新 更多