Sails OrientDB 更新错误

Sails OrientDB update error

我正在经历 this sails tutorial by irl nathan and got to a point where I wanted to try and use the sails-orientdb adaptor (episode 10)。

我解决了 orientdb id 中“#”的基本问题,但在执行更新时出现错误。

下面是代码的关键部分。

这是发布要更新的数据的编辑页面:

<form action="/user/update/<%= user.id.replace('#', '') %>" method="post" class="form-signin">
  <h2>Edit User</h2>
  <input type="text" value="<%= user.name %>" name="name" class="form-control" />
  <input type="text" value="<%= user.title %>" name="title" class="form-control" />
  <input type="text" value="<%= user.email %>" name="email" class="form-control" />
  <input type="submit" value="Proceed" class="btn btn-lg btn-primary btn-block" />
  <!--input type="hidden" value="<%= user.id  %>" name="ID" /-->
  <input type="hidden" value="<%= _csrf %>" name="_csrf" />
</form>

表单标签在浏览器中看起来像这样:

<form action="/user/update/21:0" method="post" class="form-signin">

控制器中的更新函数是这样的:

update: function (req, res, next) {
console.log("*** Update ***");
  console.log(req.params.all());
  User.update(req.param('id'), req.params.all(), function userUpdated(err) {
    console.log(err);
    if (err) return res.redirect('/user/edit/' + req.param('id'));
    return res.redirect('/user/show/' + req.param('id'));
  });//user.update
}//update

这是控制台输出:

*** Update ***
{ name: 'Test User 1',
  title: 'first ',
  email: 'test1@example.com',
  _csrf: 'irvf33GJ-CxCFmUSqmdR2WoU1K9Pw7-h8m4k',
  id: '21:0' }
Error (E_UNKNOWN) :: Encountered an unexpected error
OrientDB.RequestError: Error parsing query:
UPDATE user SET name = "Test User 1", title = "first ", email = "test1@example.com", updatedAt =     date("2016-11-15 11:05:25.165", "yyyy-MM-dd HH:mm:ss.SSS", "UTC"), @rid = 21 RETURN AFTER WHERE  @rid = "21:0"

                                               ^
Encountered " <RECORD_ATTRIBUTE> "@rid "" at line 1, column 165.
Was expecting one of:
<TO> ...
<VALUE> ...
<VALUES> ...
<SET> ...
<ADD> ...
[ a long list of expected values ] ...

        DB name="sailsTest"
    at child.Operation.parseError (C:\Development\node\sailsTestProject\sailsTestProject\node_modules\orientjs\lib\transport\binary\protocol33\operation.js:864:13)
    at child.Operation.consume (C:\Development\node\sailsTestProject\sailsTestProject\node_modules\orientjs\lib\transport\binary\protocol33\operation.js:455:35)
    at Connection.process (C:\Development\node\sailsTestProject\sailsTestProject\node_modules\orientjs\lib\transport\binary\connection.js:399:17)
    at Connection.handleSocketData (C:\Development\node\sailsTestProject\sailsTestProject\node_modules\orientjs\lib\transport\binary\connection.js:290:20)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:548:20)

Details:  OrientDB.RequestError: Error parsing query:
UPDATE user SET name = "Test User 1", title = "first ", email = "test1@example.com", updatedAt = date("2016-11-15 11:05:25.165", "yyyy-MM-dd HH:mm:ss.SSS", "UTC"), @rid = 21 RETURN AFTER WHERE  @rid =     "21:0"

                                               ^
Encountered " <RECORD_ATTRIBUTE> "@rid "" at line 1, column 165.
Was expecting one of:
<TO> ...
<VALUE> ...
<VALUES> ...
<SET> ...
<ADD> ...
[ another long list of the same expected values ] ...

    DB name="sailsTest"

更新语句是由适配器构造的,我不确定发生了什么导致错误。

我试过其他 HTTP 动词并在表单字段中提供 ID,但总是出错。 估计是params对象存储ID的方式有问题。

我该怎么做才能让它发挥作用?

2016 年 11 月 22 日更新:

对于可能感兴趣的任何人,我回滚到不同版本的 OrientDB 来试用它们。

到目前为止,OrientDB 2.0.18 似乎可以正常工作。

update 方法在使用 OrientDB 2.1.25 时有效,但 delete 方法失败。

(为了结束这个问题,我发布了自己的答案)

我回滚到 OrientDB 2.0.18 并且成功了。

以后的版本有问题。