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
5 changes: 4 additions & 1 deletion docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
- [select](api/woql.js?id=select)
- [distinct](api/woql.js?id=distinct)
- [and](api/woql.js?id=and)
- [read_object](api/woql.js?id=read_object)
- [read_document](api/woql.js?id=read_document)
- [insert_document](api/woql.js?id=insert_document)
- [update_document](api/woql.js?id=update_document)
- [delete_document](api/woql.js?id=delete_document)
- [or](api/woql.js?id=or)
- [from](api/woql.js?id=from)
- [into](api/woql.js?id=into)
Expand Down
44 changes: 43 additions & 1 deletion docs/api/woql.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ WOQL.and(
```

### read_object
#### WOQL.read\_object(IRI, output, formatObj) ⇒ <code>object</code>
#### ~~WOQL.read\_object()~~
***Deprecated***

Use [read_document](#read_document) instead.


### read_document
#### WOQL.read\_document(IRI, output, formatObj) ⇒ <code>object</code>
Read a node identified by an IRI as a JSON-LD document

**Returns**: <code>object</code> - WOQLQuery
Expand All @@ -105,6 +112,41 @@ Read a node identified by an IRI as a JSON-LD document
| formatObj | <code>object</code> | |


### insert_document
#### WOQL.insert\_document(docjson, [IRI]) ⇒ <code>object</code>
Insert a document in the graph.

**Returns**: <code>object</code> - WOQLQuery

| Param | Type | Description |
| --- | --- | --- |
| docjson | <code>object</code> | The document to insert. Must either have an '@id' or have a class specified key. |
| [IRI] | <code>string</code> | An optional identifier specifying the document location. |


### update_document
#### WOQL.update\_document(docjson, [IRI]) ⇒ <code>object</code>
Update a document identified by an IRI

**Returns**: <code>object</code> - WOQLQuery

| Param | Type | Description |
| --- | --- | --- |
| docjson | <code>object</code> | The document to update. Must either have an '@id' or have a class specified key. |
| [IRI] | <code>string</code> | An optional identifier specifying the document location. |


### delete_document
#### WOQL.delete\_document(IRI) ⇒ <code>object</code>
Delete a document from the graph.

**Returns**: <code>object</code> - WOQLQuery

| Param | Type | Description |
| --- | --- | --- |
| IRI | <code>string</code> | The document id or a variable |


### or
#### WOQL.or(...subqueries) ⇒ <code>WOQLQuery</code>
Creates a logical OR of the arguments
Expand Down
4 changes: 2 additions & 2 deletions lib/query/woqlCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function WOQLQuery(query) {
'DeleteTriple',
'AddQuad',
'DeleteQuad',
'DeleteObject',
'UpdateObject',
'DeleteDocument',
'UpdateDocument',
]

this.vocab = this.loadDefaultVocabulary()
Expand Down
50 changes: 38 additions & 12 deletions lib/query/woqlQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,49 @@ let WOQLQuery = require('./woqlCore')
}
}*/

WOQLQuery.prototype.read_object = function(IRI, OutputVar, Format) {
//if (IRI && IRI == 'args') return ['document_uri', 'document']
WOQLQuery.prototype.read_document = function(IRI, OutputVar, Format) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The definition of WOQLQuery.prototype.read_object no longer works, so, in the goal of keeping things working and compatible, can you delete the definition and add this?

WOQLQuery.prototype.read_object = WOQLQuery.prototype.read_document

For clarity, that should probably go after the WOQLQuery.prototype.read_document definition.

Copy link
Contributor Author

@Neelterminusdb Neelterminusdb Dec 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than adding this here i think it would be better if i add this

return new WOQLQuery().read_document(IRI, output, formatObj)

in here

return new WOQLQuery().read_object(IRI, output, formatObj)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but isn't WOQLQuery.prototype.read_object still wrong? We don't have ReadObject anymore.

Copy link
Contributor Author

@Neelterminusdb Neelterminusdb Dec 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup so should i just remove it ? 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, just remove it. I confirmed with @Francesca-Bit that it's no longer accessible.

if (this.cursor['@type']) this.wrapCursorWithAnd()
this.cursor['@type'] = 'ReadObject'
this.cursor['document_uri'] = this.expandValueVariable(IRI)
this.cursor['@type'] = 'ReadDocument'
this.cursor['identifier'] = this.cleanNodeValue(IRI)
this.cursor['document'] = this.expandValueVariable(OutputVar)
return this.wform(Format)
}

WOQLQuery.prototype.insert_document = function(docjson, IRI) {
if (this.cursor['@type']) this.wrapCursorWithAnd()
this.cursor['@type'] = 'InsertDocument'
if(typeof IRI !== 'undefined') this.cursor['identifier'] = this.cleanNodeValue(IRI)

if(typeof docjson === 'string') {
this.cursor['document'] = this.expandValueVariable(docjson);
} else {
this.cursor['document'] = docjson;
}

return this.updated()
}

WOQLQuery.prototype.update_document = function(docjson, IRI) {
if (this.cursor['@type']) this.wrapCursorWithAnd()
this.cursor['@type'] = 'UpdateDocument'
if(typeof IRI !== 'undefined') this.cursor['identifier'] = this.cleanNodeValue(IRI)

if(typeof docjson === 'string') {
this.cursor['document'] = this.expandValueVariable(docjson);
} else {
this.cursor['document'] = docjson;
}

return this.updated()
}

WOQLQuery.prototype.delete_document = function(IRI) {
if (this.cursor['@type']) this.wrapCursorWithAnd()
this.cursor['@type'] = 'DeleteDocument'
this.cursor['identifier'] = this.cleanNodeValue(IRI)
return this.updated()
}

/**
* Contains definitions of the WOQL functions which map directly to JSON-LD types
* All other calls and queries can be composed from these
Expand All @@ -39,14 +73,6 @@ WOQLQuery.prototype.wrapCursorWithAnd = function() {
}
}

WOQLQuery.prototype.read_object = function(IRI, OutputVar, Format) {
//if (IRI && IRI == 'args') return ['document_uri', 'document']
if (this.cursor['@type']) this.wrapCursorWithAnd()
this.cursor['@type'] = 'ReadObject'
this.cursor['document_uri'] = this.expandValueVariable(IRI)
this.cursor['document'] = this.expandValueVariable(OutputVar)
return this.wform(Format)
}

WOQLQuery.prototype.using = function(Collection, Subq) {
//if (Collection && Collection == 'args')
Expand Down
49 changes: 43 additions & 6 deletions lib/woql.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ WOQL.and = function(...subqueries) {
}


/**
* Use {@link #read_document|read_document} instead.
* @deprecated
*/

WOQL.read_object = function(IRI, output, formatObj) {
return new WOQLQuery().read_document(IRI, output, formatObj)
}

/**
* Read a node identified by an IRI as a JSON-LD document
* @param {string} IRI - The document id or a variable
Expand All @@ -99,8 +108,40 @@ WOQL.and = function(...subqueries) {
* @return {object} WOQLQuery
*/

WOQL.read_object = function(IRI, output, formatObj) {
return new WOQLQuery().read_object(IRI, output, formatObj)
WOQL.read_document = function(IRI, output, formatObj) {
return new WOQLQuery().read_document(IRI, output, formatObj)
}

/**
* Insert a document in the graph.
* @param {object} docjson - The document to insert. Must either have an '@id' or have a class specified key.
* @param {string} [IRI] - An optional identifier specifying the document location.
* @return {object} WOQLQuery
*/

WOQL.insert_document = function(docjson, IRI) {
return new WOQLQuery().insert_document(docjson, IRI)
}

/**
* Update a document identified by an IRI
* @param {object} docjson - The document to update. Must either have an '@id' or have a class specified key.
* @param {string} [IRI] - An optional identifier specifying the document location.
* @return {object} WOQLQuery
*/

WOQL.update_document = function(docjson, IRI) {
return new WOQLQuery().update_document(docjson, IRI)
}

/**
* Delete a document from the graph.
* @param {string} IRI - The document id or a variable
* @return {object} WOQLQuery
*/

WOQL.delete_document = function(IRI) {
return new WOQLQuery().delete_document(IRI)
}

/**
Expand Down Expand Up @@ -1115,10 +1156,6 @@ WOQL.string = function(val) {
return new WOQLQuery().string(val)
}

WOQL.read_object = function(IRI, output, formatObj) {
return new WOQLQuery().read_object(IRI, output, formatObj)
}

/**
* Generates explicitly a JSON-LD string literal from the input
* @param {string} val - any literal type
Expand Down
24 changes: 24 additions & 0 deletions test/woql.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,28 @@ describe('woql queries', function () {
//console.log(JSON.stringify(woqlObject01.json(), null, 4));
})

it('check the read_document method',function(){
const woqlObject=WOQL.read_document("A", "B", {});

expect(woqlObject.json()).to.eql(woqlJson.readDocJson);
})

it('check the insert_document method',function(){
const woqlObject=WOQL.insert_document("A", "B");

expect(woqlObject.json()).to.eql(woqlJson.insertDocJson);
})

it('check the update_document method',function(){
const woqlObject=WOQL.update_document("A", "B");

expect(woqlObject.json()).to.eql(woqlJson.updateDocJson);
})

it('check the delete_document method',function(){
const woqlObject=WOQL.delete_document("A");

expect(woqlObject.json()).to.eql(woqlJson.deleteDocJson);
})

})
19 changes: 19 additions & 0 deletions test/woqlJson/woqlJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -1102,4 +1102,23 @@ module.exports = {
},
],
},
readDocJson: {
'@type': 'ReadDocument',
identifier: { '@type': 'NodeValue', node: 'A' },
document: { '@type': 'Value', node: 'B' }
},
insertDocJson: {
'@type': 'InsertDocument',
identifier: { '@type': 'NodeValue', node: 'B' },
document: { '@type': 'Value', node: 'A' }
},
updateDocJson: {
'@type': 'UpdateDocument',
identifier: { '@type': 'NodeValue', node: 'B' },
document: { '@type': 'Value', node: 'A' }
},
deleteDocJson: {
'@type': 'DeleteDocument',
identifier: { '@type': 'NodeValue', node: 'A' },
},
}