【问题标题】:can we give time after inserting data in mysql table using sequelize js node我们可以在使用 sequelize js 节点在 mysql 表中插入数据后给时间吗
【发布时间】:2019-08-09 20:08:29
【问题描述】:

我在 MySQL 中创建了一个订单表,其中包含 start timeclose time 等字段,使用这些字段我需要在将数据插入订单表后给订单表插入数据的时间。

有可能吗?

如果是,请帮助我如何解决它。

【问题讨论】:

  • 请举例说明你想在表格中显示什么

标签: mysql node.js sequelize.js


【解决方案1】:

恕我直言,您的问题让我们猜测您想做什么。

您可以通过执行以下操作将当前时间插入一行:

  INSERT INTO orders (start_time, col1, col2) 
         VALUES (NOW(), 'something', 'another thing');

你可以像这样更新一行来设置现在时间

  UPDATE orders SET close_time=NOW(), col2='some value'
   WHERE col1='something';

通过像这样声明 start_time 行,您可以在插入时自动设置当前时间:

start_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

但您可能需要根据您的业务逻辑自行设置close_time。

如果您的 start_timeclose_time 列是使用 TIMESTAMP 数据类型定义的,那么在处理多个时区时会获得一些优势。

(start_time, col1, col2) VALUES (NOW(), 'something', 'another thing');

【讨论】:

  • hii jones... 响应的坦克
  • pastebin.com/WqJVp9D3 请检查我清楚地提到我的问题的链接
  • 请提出另一个问题,并在问题的文本中包含您的 pastebin 中的所有内容。
猜你喜欢
  • 1970-01-01
  • 2019-12-23
  • 2022-06-14
  • 1970-01-01
  • 2018-08-17
  • 2017-12-03
  • 1970-01-01
  • 2018-12-29
  • 1970-01-01
相关资源
最近更新 更多