Skip to content

Commit 810897f

Browse files
Merge pull request #34 from fidelthomet/master
[Feature] extend capabilities of `insert_data`
2 parents 9384c24 + 7a3b6de commit 810897f

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

lib/query/woqlBuilder.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,32 @@ WOQLQuery.prototype.insert_data = function(data, refGraph) {
171171
type = this.cleanType(data.type, true)
172172
this.insert(data.id, type, refGraph)
173173
if (data.label) {
174-
this.label(data.label)
174+
if (Array.isArray(data.label)) {
175+
data.label.forEach(value => {
176+
this.label(value)
177+
})
178+
} else {
179+
this.label(data.label)
180+
}
175181
}
176182
if (data.description) {
177-
this.description(data.description)
183+
if (Array.isArray(data.description)) {
184+
data.description.forEach(value => {
185+
this.description(value)
186+
})
187+
} else {
188+
this.description(data.description)
189+
}
178190
}
179191
for (var k in data) {
180192
if (['id', 'label', 'type', 'description'].indexOf(k) == -1) {
181-
this.property(k, data[k])
193+
if (Array.isArray(data[k])) {
194+
data[k].forEach(value => {
195+
this.property(k, value)
196+
})
197+
} else {
198+
this.property(k, data[k])
199+
}
182200
}
183201
}
184202
}
@@ -232,8 +250,9 @@ WOQLQuery.prototype.domain = function(d) {
232250
* @param {string} [lang] - the label language
233251
*/
234252

253+
235254
WOQLQuery.prototype.label = function(labelVar, lang = 'en') {
236-
if (labelVar.substring(0, 2) == 'v:') {
255+
if (typeof labelVar === 'object' || labelVar.substring(0, 2) == 'v:') {
237256
var d = labelVar
238257
} else {
239258
var d = {'@value': labelVar, '@type': 'xsd:string', '@language': lang}
@@ -243,7 +262,7 @@ WOQLQuery.prototype.label = function(labelVar, lang = 'en') {
243262

244263
WOQLQuery.prototype.description = function(c, lang) {
245264
lang = lang ? lang : 'en'
246-
if (c.substring(0, 2) == 'v:') {
265+
if (typeof c === 'object' || c.substring(0, 2) == 'v:') {
247266
var d = c
248267
} else {
249268
var d = {'@value': c, '@type': 'xsd:string', '@language': lang}

0 commit comments

Comments
 (0)