sage icon indicating copy to clipboard operation
sage copied to clipboard

Raw Return

Open sourcec0de opened this issue 12 years ago • 2 comments

Im not able to find any documentation for this anywhere. Im trying to get sage to return the full raw data because I want the match count.

sourcec0de avatar Mar 04 '13 19:03 sourcec0de

Sorry about the lack of documentation... you should be able to access the total count via data.total and the raw JSON via data.json. The returned object's prototype is extended to have these properties here:

https://github.com/mikepb/sage/blob/master/sage.js#L291

        data = [].slice.call(data);
        extend(data.__proto__ = [], json, json.hits).json = json;

As part of the prototype, the properties aren't enumerated when printed to console. Using __proto__ may not work in all browsers (e.g. IE), but works in Node.js and V8.

This was a convenience pattern borrowed from Cradle.

I have considered setting the properties directly on the result array or just returning the raw data, depending on how people use the library.

mikepb avatar Mar 07 '13 17:03 mikepb

@skyteclabs I started documenting Sage at mikepb.github.com/sage. It's a work in progress; let me know what you think.

mikepb avatar Mar 11 '13 03:03 mikepb