neumino / thinky

JavaScript ORM for RethinkDB
http://justonepixel.com/thinky/
Other
1.12k stars 128 forks source link

getAll returns results in reThink database explorer, but empty array with Thinky #641

Closed JBorgia closed 6 years ago

JBorgia commented 6 years ago

Hello. First, much thanks for taking the time to read my issue. When I run the following on my database via the rethink database explorer, it get 2 objects back:

r.db('test').table('stb').getAll(r.args(["000b0d40-8592-42f3-9c31-b69f939ec2d6","001fee75-c755-44c3-8c9f-f32a8db37ba1"]))

However, when I run the following from my controller for the 'stb' table, I get an empty array back.

Stb.getAll(req.params.ids).run(function(err, res) { console.log('err: ', err); console.log('res: ', err); });

other variations with r.args gets nothing. The query just times out. Not sure what I am doing wrong:

Stb.getAll(r.args(req.params.ids)).run(function(err, res) { console.log('err: ', err); console.log('res: ', err); });

req.params.ids = ["000b0d40-8592-42f3-9c31-b69f939ec2d6","001fee75-c755-44c3-8c9f-f32a8db37ba1"]

Also tried JSON.parse(req.params.ids) to no avail.

JBorgia commented 6 years ago

Update: I have managed to get results back if I enter the ids as so:

Stb.getAll('000b0d40-8592-42f3-9c31-b69f939ec2d6', '001fee75-c755-44c3-8c9f-f32a8db37ba1').run().then(function(err, res) { console.log('err2: ', err); console.log('res2: ', res); });

however, I cannot get anything back if requested using r.args.

Stb.getAll(r.args(['000b0d40-8592-42f3-9c31-b69f939ec2d6', '001fee75-c755-44c3-8c9f-f32a8db37ba1'])).run().then(function(err, res) { console.log('err2: ', err); console.log('res2: ', res); });

Declarations at the top of my file:

const thinky = require('../util/thinky.js'); const r = thinky.r; const Stb = require('../models/stb');

where thinky.js is defined as

var thinky = require('thinky')({
host: 'localhost',
port: '28015',
db: 'test'
});

exports.thinky = thinky;
grantcarthew commented 6 years ago

I remember having this issue @JBorgia. Thinky doesn't support an array of arguments if I recall. Either use apply or destructure the array ...args.

JBorgia commented 6 years ago

@grantcarthew, Thanks man. I had tried apply with no luck, but the spread operator (...args) worked fine. Wish more of this was in the documentation.