Skip to content

Commit

Permalink
getColumns... -- respect ?select(...), not the very first record extr…
Browse files Browse the repository at this point in the history
…acted
  • Loading branch information
dvv committed Jul 19, 2010
1 parent 6b8f3fb commit 5f404bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
5 changes: 4 additions & 1 deletion lib/jsgi/rest-store.js
Expand Up @@ -61,7 +61,10 @@ exports.RestStore = function(options){
// handle the range header, TODO: maybe handle ranges with another piece of middleware
// N.B. nomatter valid Range: is present, let's honor store.maxLimit, if any
var limit = Math.min(store.maxLimit||Infinity, store.defaultLimit||Infinity) || Infinity;
var maxCount = 0; // don't trigger totalCount evaluation unless a valid Range: is seen
//// N.B. limitation due to store.maxLimit assumes a Range:
//// don't trigger totalCount evaluation unless a valid Range: is seen or limit is set
////var maxCount = (limit !== Infinity) ? Infinity : 0;
var maxCount = 0; // don't trigger totalCount evaluation unless a valid Range: is seen or limit is set
var start = 0;
var end = Infinity;
if (metadata.range) {
Expand Down
1 change: 1 addition & 0 deletions lib/jsgi/templated.js
Expand Up @@ -48,6 +48,7 @@ exports.Templated = function(options, nextApp){
// vanilla HTML -> wrap it in template
var vars = ((typeof options.vars === 'function') ? options.vars(request) : options.vars) || {};
vars.content = media.forEachableToString(response.body);
//dir('CONTENT', response.body, vars.content);
var b = exports.renderPartial(options.template || 'index.html', vars);
//dir('BODY', b);
response.body = b;
Expand Down
18 changes: 5 additions & 13 deletions lib/media.js
Expand Up @@ -81,19 +81,11 @@ Media.optimumMedia = function(source, acceptTypeHeader){
exports.getColumnsToExport = function(request, item){
var columns = [];
// honor possible ?select(prop1,prop2,...)
if (item && typeof item.hasOwnProperty === 'function') {
require('rql/parser').parseQuery(request.queryString).args.forEach(function(term){
if (term.name === 'select') {
columns = [];
term.args.forEach(function(f){
if (item.hasOwnProperty(f))
columns.push(f);
});
} else if (term.name === 'values') {
columns = term.args;
}
});
}
require('rql/parser').parseQuery(request.queryString).args.forEach(function(term){
if (term.name === 'select' || term.name === 'values') {
columns = term.args;
}
});
// no (valid) ?select(...) -> dump all properties
if (columns.length === 0 && item && typeof item === 'object')
columns = Object.keys(item);
Expand Down

0 comments on commit 5f404bc

Please sign in to comment.