Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 41 additions & 50 deletions data-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,70 +825,61 @@ function filterInternal(params, callback) {
q.query.$expand = $joinExpressions;
//prepare
q.query.prepare();

if (typeof params === 'object') {
//apply query parameters
var select = params.$select,
skip = params.$skip || 0,
orderBy = params.$orderby || params.$order,
groupBy = params.$groupby || params.$group,
orderBy = params.$orderby || params.$orderBy || params.$order,
groupBy = params.$groupby || params.$groupBy || params.$group,
expand = params.$expand,
levels = parseInt(params.$levels),
top = params.$top || params.$take;
//select fields
if (typeof select === 'string') {
q.select.apply(q, select.split(',').map(function(x) {
return x.replace(/^\s+|\s+$/g, '');
}));
}
//apply group by fields
if (typeof groupBy === 'string') {
q.groupBy.apply(q, groupBy.split(',').map(function(x) {
return x.replace(/^\s+|\s+$/g, '');
}));
}
if ((typeof levels === 'number') && !isNaN(levels)) {
//set expand levels
q.levels(levels);
}
//set $skip
q.skip(skip);
if (top)
q.query.take(top);
//set caching
if (params.$cache && self.caching === 'conditional') {
q.cache(true);
}
//set $orderby
if (orderBy) {
orderBy.split(',').map(function(x) {
return x.replace(/^\s+|\s+$/g, '');
}).forEach(function(x) {
if (/\s+desc$/i.test(x)) {
q.orderByDescending(x.replace(/\s+desc$/i, ''));

void async.series(
[
function(cb) { return parser.parseSelectSequence(select, cb) },
function(cb) { return parser.parseOrderBySequence(orderBy, cb) },
function(cb) { return parser.parseSelectSequence(groupBy, cb) },
function(cb) {
return cb(null, parser.parseExpandSequence(expand));
}
else if (/\s+asc/i.test(x)) {
q.orderBy(x.replace(/\s+asc/i, ''));
], function (err, results) {
if (err) {
return callback(err);
}
else {
q.orderBy(x);
// get select, orderby and groupby system query options
var [$select, $orderBy, $groupBy, $expand] = results;
Object.assign(q.query, {
$select,
$orderBy,
$groupBy
});
// set levels
if ((typeof levels === 'number') && !isNaN(levels)) {
q.levels(levels);
}
});
}
if (expand) {

var resolver = require('./data-expand-resolver');
var matches = resolver.testExpandExpression(expand);
if (matches && matches.length>0) {
q.expand.apply(q, matches);
// set top
if (top) {
q.take(top);
}
// set skip
q.skip(skip);
//set caching
var { $cache } = params;
if ($cache && self.caching === 'conditional') {
q.cache(true);
}
// set expand
if ($expand) {
q.expand.apply(q, $expand);
}
return callback(null, q);
}
}
//return
callback(null, q);
)
}
else {
//and finally return DataQueryable instance
callback(null, q);
return callback(null, q);
}

}
Expand Down
49 changes: 34 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"peerDependencies": {
"@themost/common": "^2.5.11",
"@themost/query": "^2.5.27",
"@themost/query": "^2.5.29",
"@themost/xml": "^2.5.2"
},
"engines": {
Expand Down Expand Up @@ -43,7 +43,7 @@
"@themost/common": "^2.5.11",
"@themost/json-logger": "^1.1.0",
"@themost/peers": "^1.0.2",
"@themost/query": "^2.5.27",
"@themost/query": "^2.5.29",
"@themost/sqlite": "^2.6.16",
"@themost/xml": "^2.5.2",
"@types/core-js": "^2.5.0",
Expand Down