petersirka / nosql

NoSQL embedded database for small node.js projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Another question - response object

biomade opened this issue · comments

I can now query my little db and so how do I access the value pairs.
Here is what is in the authors table

{"id":1,"name":"laurie","email":"laurie@gmail.com"}
{"id":2,"name":"erich","email":"erich@gmail.com"}

Here is my code

var dbauthors = db.load('db/authors.nosql');
//insert two records
//dbauthors.insert({ id: 1, name: 'laurie', email: 'laurie@gmail.com'} ) 
//dbauthors.insert({ id: 2, name: 'erich', email: 'erich@gmail.com' }) 
//console.log("inserted two records in authors");
//now find the second author
dbauthors.find().make(function(builder) {
    builder.where('id', 2);
    builder.callback(function(err, response) {
        console.log('users between 2 and 4:', response);
        console.log('users email:', response.email)
    });
});

And what I get in the console.
users between 2 : [ { id: 2, name: 'erich', email: 'erich@gmail.com' } ]
users email: undefined

dbauthors.find().make(function(builder) {
    builder.where('id', 2);
    builder.first(); // nosql returns only the first item (so in the response won't be an array)
    builder.callback(function(err, response) {
        console.log('users between 2 and 4:', response);

        // because response was array
        console.log('users email:', response.email)
    });
});

Thanks so much for your help. I will add this to my testing code.