Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 使用Postgres&;更新表中的日期时间值;捏_Postgresql_Knex.js - Fatal编程技术网

Postgresql 使用Postgres&;更新表中的日期时间值;捏

Postgresql 使用Postgres&;更新表中的日期时间值;捏,postgresql,knex.js,Postgresql,Knex.js,我想将“访问令牌”过期日期时间更新到“用户”表中,以便检查访问令牌是否有效以重置密码。 因此,我使用矩传递一个datetime字符串值 但它无法更新datetime,并且没有错误消息 “forgotPassword”函数在不更新“resetPasswordExpires”的情况下工作 我已尝试将“resetPasswordExpires”列类型设置为timeStamp。它不起作用 [ Front-End ] const inOneHour = moment() .add(1, 'hours'

我想将“访问令牌”过期日期时间更新到“用户”表中,以便检查访问令牌是否有效以重置密码。 因此,我使用矩传递一个datetime字符串值

但它无法更新datetime,并且没有错误消息

“forgotPassword”函数在不更新“resetPasswordExpires”的情况下工作

我已尝试将“resetPasswordExpires”列类型设置为timeStamp。它不起作用

[ Front-End ]
const inOneHour = moment()
  .add(1, 'hours')
  .format('MMMM Do YYYY, HH:mm:ss');


[ users table / Database ]
table.datetime('resetPasswordExpires', { useTz: false });

谢谢

好吧,我确信它失败了,只是你没有捕捉到异常

首先为KNEX添加错误处理程序

return knex('users')
          .where({ username })
          .first()
          .update({
            resetPasswordToken: token,
            resetPasswordExpires: inOneHour,
          })
          .then(() => {
            // Do your work
          })
          .catch((err) => {
            // print out the error
          });
现在来看解决方案,日期的格式,即
.format('MMMM Do YYYY,HH:mm:ss'),因此您将无法使用此格式。
您当前的格式生成类似于2019年7月18日19:03:41的输出

您可以使用
.format('MMMM-DD-YYYY,HH:mm:ss')首先,创建日期为2019年7月18日19:03:41
。但是我建议您只需执行
.format()
,这样您就不必担心每次在代码中使用它时的格式

return knex('users')
          .where({ username })
          .first()
          .update({
            resetPasswordToken: token,
            resetPasswordExpires: inOneHour,
          })
          .then(() => {
            // Do your work
          })
          .catch((err) => {
            // print out the error
          });