Search code examples
sails.jsorientdbwaterlinesails-orientdb

Sails OrientDB update error


I'm going through this sails tutorial by irl nathan and got to a point where I wanted to try and use the sails-orientdb adaptor (episode 10).

I resolved the basic issues with the '#' in orientdb id's but I'm getting an error when executing an update.

Here are the key parts of the code.

This is the edit page which posts the data to update:

<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>

The form tag looks like this in the browser:

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

The update function in the controller is this:

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

This is the console output:

*** Update ***
{ name: 'Test User 1',
  title: 'first ',
  email: '[email protected]',
  _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 = "[email protected]", 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 = "[email protected]", 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"

The update statement is constructed by the adaptor, and I'm not sure what is happening to cause the error.

I've tried other HTTP verbs and providing the ID in a form field but always get errors. I guess that there is a problem with the way the ID is stored in the params object.

What can I do to make it work?

UPDATE 22 Nov 2016:

For anyone that might be interested I rolled back to different versions of OrientDB to try them out.

So far OrientDB 2.0.18 seems to work.

The update method works when using OrientDB 2.1.25 but the delete method failed.


Solution

  • (In order to wrap up this question I am posting my own answer)

    I rolled back to OrientDB 2.0.18 and it worked.

    Later versions had issues.