Skip to content

Commit 10d51fe

Browse files
Merge pull request #169 from terminusdb/doc_template_fixes
Adding document templating fixes
2 parents 57c6e29 + ef15df7 commit 10d51fe

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

lib/query/woqlCore.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ WOQLQuery.prototype.jobj = function (qobj) {
159159
/**
160160
* Wraps the elements of an AS variable in the appropriate json-ld
161161
*/
162-
WOQLQuery.prototype.asv = function (colname_or_index, vname, type) {
162+
WOQLQuery.prototype.asv = function (colname_or_index, variable, type) {
163163
const asvar = {};
164164
if (typeof colname_or_index === 'number') {
165165
asvar['@type'] = 'Column';
@@ -168,8 +168,13 @@ WOQLQuery.prototype.asv = function (colname_or_index, vname, type) {
168168
asvar['@type'] = 'Column';
169169
asvar.indicator = { '@type': 'Indicator', name: colname_or_index };
170170
}
171-
if (vname.substring(0, 2) === 'v:') vname = vname.substring(2);
172-
asvar.variable = vname;
171+
if (variable instanceof Var) {
172+
asvar.variable = variable.name;
173+
} else if (variable.substring(0, 2) === 'v:') {
174+
asvar.variable = variable.substring(2);
175+
} else {
176+
asvar.variable = variable;
177+
}
173178
if (type) asvar.type = type;
174179
return asvar;
175180
};

lib/query/woqlDoc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ function convert(obj) {
2626
'@value': obj,
2727
},
2828
};
29+
// eslint-disable-next-line no-use-before-define
30+
} if (obj instanceof Var) {
31+
return {
32+
'@type': 'Value',
33+
variable: obj.name,
34+
};
2935
} if (typeof (obj) === 'object') {
3036
const pairs = [];
3137
// eslint-disable-next-line no-restricted-syntax

lib/query/woqlQuery.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/// /@ts-check
1313
// WOQLQuery
1414
const WOQLQuery = require('./woqlCore');
15+
const { Var, Doc } = require('./woqlDoc');
1516

1617
// I HAVE TO REVIEW THE Inheritance and the prototype chain
1718
/* class WOQLQuery extends WOQLCore {
@@ -376,10 +377,15 @@ WOQLQuery.prototype.put = function (asvars, query, query_resource) {
376377
*
377378
* Imports the value identified by Source to a Target variable
378379
*
379-
* calling:
380+
* Examples:
381+
*
380382
* WOQL.as("first var", "v:First_Var", "string").as("second var", "v:Second_Var")
383+
*
381384
* WOQL.as(["first var", "v:First_Var", "string"], ["second var", "v:Second_Var"])
382385
*
386+
* let [First_Var,Second_Var] = WOQL.vars("First_Var","Second_Var")
387+
* WOQL.as("first var", First_Var, "string").as("second var", Second_Var)
388+
*
383389
* @param {...(array|string)} varList variable number of arguments
384390
* @returns WOQLQuery
385391
*/
@@ -407,6 +413,8 @@ WOQLQuery.prototype.as = function (...varList) {
407413
} else if (typeof varList[0] === 'number' || typeof varList[0] === 'string') {
408414
if (varList[2] && typeof varList[2] === 'string') {
409415
var oasv = this.asv(varList[0], varList[1], varList[2]);
416+
} else if (varList[1] && varList[1] instanceof Var) {
417+
var oasv = this.asv(varList[0], varList[1]);
410418
} else if (varList[1] && typeof varList[1] === 'string') {
411419
if (varList[1].substring(0, 4) === 'xsd:' || varList[1].substring(0, 4) === 'xdd:') {
412420
var oasv = this.asv(this.query.length, varList[0], varList[1]);

0 commit comments

Comments
 (0)