Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sequences return raw time format instead of native #14

Closed
chrisvariety opened this issue Apr 19, 2014 · 4 comments
Closed

sequences return raw time format instead of native #14

chrisvariety opened this issue Apr 19, 2014 · 4 comments

Comments

@chrisvariety
Copy link

Hi,

Spent my afternoon tracking down this weird bug...

var co = require('co');
var rethinkdbdash = require('rethinkdbdash-unstable');
var r = rethinkdbdash({db: 'test'});

co(function *() {
  yield r.tableCreate('testing').run();
  yield r.table('testing').indexCreate('companyId').run();
  yield r.table('testing').insert({companyId: '1', createdAt: r.now()}).run();
  var cursor = yield r.table('testing').getAll('1', {index: 'companyId'}).run({timeFormat: 'native'});
  var result = yield cursor.toArray();
  console.log('result', result);
})();

Result is:

result [ { companyId: '1',
    createdAt: 
     { '$reql_type$': 'TIME',
       epoch_time: 1397950623.646,
       timezone: '+00:00' },
    id: '0a3beb01-fb42-4e80-9eb7-c2d4be17439e' } ]

Notice the time format is raw, even though I am specifying native. Leaving timeFormat unspecified (e.g. just .run()) should default to native, but still returns a raw time.

This seems to happen anytime I get a sequence back. I believe we're just missing a call to pb.convertPseudoType somewhere in here: https://github.com/neumino/rethinkdbdash/blob/master/lib/protobuf.js#L90-L97

Node v0.11.10
rethinkdbdash v1.12.4

@chrisvariety chrisvariety changed the title indexed getAll returns raw time format instead of native sequences return raw time format instead of native Apr 20, 2014
@chrisvariety
Copy link
Author

This seems to fix it:

diff --git a/node_modules/rethinkdbdash-unstable/lib/protobuf.js b/node_modules/rethinkdbdash-unstable/lib/protobuf.js
index e40f1d6..08d1d13 100644
--- a/node_modules/rethinkdbdash-unstable/lib/protobuf.js
+++ b/node_modules/rethinkdbdash-unstable/lib/protobuf.js
@@ -93,7 +93,7 @@ pb.makeSequence = function(response, options) {
     for(var i=0; i<response.response.length; i++) {
         result.push(pb.makeDatum(response.response[i], options));
     }
-    return result;
+    return pb.convertPseudoType(result, options);
 }

neumino added a commit that referenced this issue Apr 20, 2014
@chrisvariety
Copy link
Author

Looks like you arrived at the same conclusion... except better... thanks so much @neumino you are ridiculously responsive.

@neumino
Copy link
Owner

neumino commented Apr 20, 2014

Sorry for the bug @chrisvariety.
Cursors were indeed not convertying pseudo types. Your fix is exactly what I did :)

@chrisvariety -- I just pushed 1.12.5 with the fix for dates.

@chrisvariety
Copy link
Author

@neumino Thanks again !! Working super great now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants