Skip to content

Commit 61a1a05

Browse files
adding fix for .when()
1 parent dac90df commit 61a1a05

File tree

1 file changed

+78
-3
lines changed

1 file changed

+78
-3
lines changed

lib/woql.js

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ WOQL.as = function(map, vari){ return new WOQLQuery().as(map, vari); }
4444
WOQL.remote = function(url){ return new WOQLQuery().remote(url); }
4545
WOQL.unique = function(prefix, vari){ return new WOQLQuery().unique(prefix, vari); }
4646
WOQL.list = function(...vars){ return new WOQLQuery().list(...vars); }
47+
WOQL.group_by = function(...vars){ return new WOQLQuery().group_by(...vars); }
48+
WOQL.update = function(Q){ return new WOQLQuery().update(Q); }
49+
4750

4851
//language extensions that can be chained after 'grounded' stuff (clauses with a specific subject) sub, isa, delete_triple, add_triple, delete_quad, add_quad, node
4952
//WOQL.value = function(vars){ return new WOQLQuery().list(vars); }
@@ -92,15 +95,83 @@ function WOQLQuery(query){
9295
}
9396

9497
WOQLQuery.prototype.get = function(map, target){
95-
this.cursor['get'] = [map, target];
98+
if(target){
99+
this.cursor['get'] = [map, target];
100+
}
101+
else {
102+
this.cursor['get'] = [map];
103+
this.cursor = this.cursor["get"][1];
104+
}
96105
return this;
97106
}
98107

108+
WOQLQuery.prototype.concat = function(list, v){
109+
this.cursor['concat'] = [list, v];
110+
return this;
111+
}
112+
113+
WOQLQuery.prototype.lower = function(u, l){
114+
this.cursor['lower'] = [u, l];
115+
return this;
116+
}
117+
118+
WOQLQuery.prototype.pad = function(input, pad, len, output){
119+
this.cursor['pad'] = [input, pad, len, output];
120+
return this;
121+
}
122+
123+
WOQLQuery.prototype.join = function(...list){
124+
this.cursor['join'] = list;
125+
return this;
126+
}
127+
128+
129+
//concat() //"concat" : [{"list" : ["doc:", "v:Polity_Lower"]}, "v:Polity_ID"]},
130+
/**
131+
* [{"list" : [{"@value" : "[", "@type" : "xsd:string"},
132+
"v:GYear",
133+
{"@value" : ",","@type" : "xsd:string"},
134+
"v:GYear",
135+
{"@value" : "]","@type" : "xsd:string"}]
136+
*/
137+
//lower(v1, v2) ["v:Polity", "v:Polity_Lower"]
138+
//pad(var,pad,len,nvar]) ["v:Year",0,4,"v:GYear"]
139+
//unique(prefix, vars, type)
140+
//group_by
141+
//file
142+
//join(...x)
143+
//{"join" : ["v:Records",
144+
//{"@value" : ",", "@type" : "xsd:string"},
145+
//"v:Coord_String"
146+
//]},
147+
99148
WOQLQuery.prototype.remote = function(json){
100149
this.cursor['remote'] = [json];
101150
return this;
102151
}
103152

153+
WOQLQuery.prototype.group_by = function(...grouped){
154+
var ngs = [];
155+
for(var i = 0; i<grouped.length; i++){
156+
ngs.push(grouped[i].json());
157+
}
158+
this.cursor['group_by'] = ngs;
159+
this.cursor = this.cursor["group_by"][ngs.length];
160+
return this;
161+
}
162+
163+
164+
WOQLQuery.prototype.unique = function(prefix, vari, type){
165+
this.cursor['unique'] = [prefix, vari, type];
166+
return this;
167+
}
168+
169+
WOQLQuery.prototype.list = function(...vars){
170+
this.cursor['list'] = vars;
171+
return this;
172+
}
173+
174+
104175
/*
105176
* json version of query for passing to api
106177
*/
@@ -117,9 +188,14 @@ WOQLQuery.prototype.json = function(json){
117188
* into the corrent place in the encompassing json
118189
*/
119190
WOQLQuery.prototype.when = function(Query, Update){
191+
if(typeof Query == "boolean") {
192+
var jq = {};
193+
jq[Query] = [];
194+
Query = jq;
195+
}
120196
this.advanceCursor("when", Query);
121197
if(Update){
122-
this.cursor = Update.json();
198+
this.cursor = (Update.json ? Update.json() : Update);
123199
}
124200
return this;
125201
}
@@ -381,7 +457,6 @@ WOQLQuery.prototype.as = function(a, b){
381457
return this.lastUpdate();
382458
}
383459

384-
385460
/**
386461
* WOQL API
387462
*/

0 commit comments

Comments
 (0)