Skip to content
Merged
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
4 changes: 2 additions & 2 deletions lib/query/woqlPrinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ WOQLPrinter.prototype.pvar = function(json) {
//if (json['woql:variable_name'] && typeof json['woql:variable_name']['@value'] != 'undefined') {
if(json['variable']){
let varname = json['variable']
let order = json['order'] ? ` ${json['order']}` : ''
let order = json['order'] ? json['order'] : ''
if (varname.indexOf(':') === -1) {
varname = 'v:' + varname
}
return `"${varname}${order}"`
return (order!=='' && order!=='asc') ? `["${varname}","${order}"]` : `"${varname}"`;
}else if (json['node']){
return `"${json['node']}"`
}else if (json['data'] ){
Expand Down
22 changes: 17 additions & 5 deletions lib/query/woqlQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,16 +886,28 @@ WOQLQuery.prototype.order_by = function(...orderedVarlist) {
: false

for (var i = 0; i < orderedVarlist.length; i++) {
if (typeof orderedVarlist[i] == 'string'){
let obj = {
let obj;
if (typeof orderedVarlist[i] == 'string' && orderedVarlist[i] !== ""){
obj = {
'@type': 'OrderTemplate',
'variable': this.rawVar(orderedVarlist[i]),
'order': "asc"
}
this.cursor['ordering'].push(obj)
}else{
this.cursor['ordering'].push(orderedVarlist[i])
} else if(orderedVarlist[i].length === 2 && orderedVarlist[i][1] === 'asc'){
obj = {
'@type': 'OrderTemplate',
'variable': this.rawVar(orderedVarlist[i][0]),
'order': "asc"
}
} else if(orderedVarlist[i].length === 2 && orderedVarlist[i][1] === 'desc'){
obj = {
'@type': 'OrderTemplate',
'variable': this.rawVar(orderedVarlist[i][0]),
'order': "desc"
}
}

if(obj) this.cursor['ordering'].push(obj);
}
return this.addSubQuery(embedquery)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/woql.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,10 @@ WOQL.cast = WOQL.typecast

/**
* Orders the results of the contained subquery by a precedence list of variables
* @param {...string} varNames - A sequence of variables, by which to order the results, each optionally followed by either “asc” or “desc” to represent order
* @param {...string} varNames - A sequence of variables, by which to order the results, each optionally followed by either “asc” or “desc” to represent order as a list, by default it will sort the variable in ascending order
* @returns {WOQLQuery} A WOQLQuery which contains the ordering expression
* @example
* WOQL.order_by("v:A", "v:B asc", "v:C desc").triple("v:A", "v:B", "v:C");
* WOQL.order_by("v:A", ["v:B", "asc"], ["v:C", "desc"]).triple("v:A", "v:B", "v:C");
*/
WOQL.order_by = function(...varNames) {
return new WOQLQuery().order_by(...varNames)
Expand Down