michaelwittig / node-q

Q interfacing with Node.js
MIT License
52 stars 14 forks source link

Command getting corrupted through serialisation? #8

Closed richardbutler closed 8 years ago

richardbutler commented 8 years ago

I'm trying to query a function, which would be called q-side like this (this would return me a table):

q) `.xyz.getTrades; `VOD.L, 2015.07.08; 0t; 2015.07.09; 24t; ()!()

However, I've tried a few variations, such as the below (and every permutation between symbols, date objects, strings, etc) with nodeq.k without success, but I'm not sure which part is getting corrupted as KDB errors are, well, you know :)

nodeq.k('.xyz.getTrades', ['`VOD.L', '2015.07.08', '0t', '2015.07.09', '24t', {}], function ...

nodeq.k('.xyz.getTrades', ['VOD.L', '2015.07.08', '0t', '2015.07.09', '24t', '()!()'], function ...

nodeq.k('`.xyz.getTrades', ['`VOD.L', new Date(2015, 6, 8), '0t', new Date(2015, 6, 9), '24t', {}], function ...

nodeq.k('`.xyz.getTrades' ['`VOD.L; 2015.07.08; 0t; 2015.07.09; 24t; ()!()'], function ...

And also the full command as a string:

nodeq.k('`.xyz.getTrades; `VOD.L; 2015.07.08; 0t; 2015.07.09; 24t; ()!()', function ...

nodeq.k('.xyz.getTrades; `VOD.L; 2015.07.08; 0t; 2015.07.09; 24t; ()!()', function ...

I get varying errors but mostly badreq. Is there something obvious that I'm doing wrong here?

michaelwittig commented 8 years ago

what about

nodeq.k(".xyz.getTrades[`VOD.L;2015.07.08;0t;2015.07.09;24t;()!()]", function(err, res) { ... });
richardbutler commented 8 years ago

No joy, but I did find out the cause of the problem. This one gets through:

nodeq.k('`xyz.getTrades', '`VOD.L', new Date(2015, 6, 8), '0t', new Date(2015, 6, 9), '24t', {}, function ...

But time values, e.g. 0t, 24t, are getting sent to Q as strings. How would you expect c.js to handle those?

michaelwittig commented 8 years ago

the problem is, that JavaScript does not have as much types as q have. e.g. we have no type for times.

I made a slight mistake is my previous line (edited this one as well), this one should work:

nodeq.k(".xyz.getTrades[`VOD.L;2015.07.08;0t;2015.07.09;24t;()!()]", function(err, res) { ... });

Providing a string that is then evaluated as q code on the q side is at the moment the version that gives you the most control.

richardbutler commented 8 years ago

Bingo. Thanks!

michaelwittig commented 8 years ago

always happy to see someone using q/kdb+ :)