1

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: '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"

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.

Walter Sung
  • 140
  • 9
  • 1
    The correct generated query should be 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") RETURN AFTER WHERE @rid = "21:0" – Alessandro Rota Nov 15 '16 at 13:28
  • Thanks Allessandro, the update statement is composed by the sails-orientdb adaptor, i haven't written a custom function. Have I configured the adaptor wrong or perhaps supplying the parameters incorrectly? – Walter Sung Nov 16 '16 at 02:01
  • Oops, realised I should have added @AlessandroRota to previous comment :) – Walter Sung Nov 16 '16 at 08:49
  • Which version of OrientDB are you using? Sails-orientdb only supports OrientDB up to v2.0. More details at https://github.com/appscot/sails-orientdb/issues/52 – Dário Nov 16 '16 at 12:13
  • @Dário I'm using OrientDB 2.2.12-SNAPSHOT, sails-orientdb v0.10.60, and sails 0.12.9. Is there an updated orientdb adaptor, or do I need to downgrade to an earlier version of orientdb? – Walter Sung Nov 17 '16 at 02:21
  • @WalterSung, your best chance is to downgrade OrientDB to v2.0. I'm not aware of any alternative adaptors. – Dário Nov 18 '16 at 15:14
  • Thanks @Dário for your help, I might try to downgrade orientdb or maybe even try neo4j or arango – Walter Sung Nov 19 '16 at 13:53

1 Answers1

2

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

Walter Sung
  • 140
  • 9