Skip to content

Commit 4a0078b

Browse files
added examples for dataversion docs (#147)
Signed-off-by: NeelParihar <[email protected]>
1 parent 93b9748 commit 4a0078b

File tree

2 files changed

+392
-44
lines changed

2 files changed

+392
-44
lines changed

docs/api/woqlClient.js.md

Lines changed: 196 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,16 @@ client.updateTriples("schema", "alt", turtle_string, "dumping triples to graph a
148148
##### woqlClient.query(woql, [commitMsg], [allWitnesses], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
149149
Executes a WOQL query on the specified database and returns the results
150150

151-
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
151+
**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
152+
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
152153

153154
| Param | Type | Description |
154155
| --- | --- | --- |
155156
| woql | <code>WOQLQuery</code> | an instance of the WOQLQuery class |
156157
| [commitMsg] | <code>string</code> | a message describing the reason for the change that will be written into the commit log (only relevant if the query contains an update) |
157158
| [allWitnesses] | <code>boolean</code> | |
158-
| [lastDataVersion] | <code>string</code> | If passed it will be used for data version tracking |
159-
| [getDataVersion] | <code>string</code> | If true it the function will return object having result and dataVersion |
159+
| [lastDataVersion] | <code>string</code> | the last data version tracking id. |
160+
| [getDataVersion] | <code>boolean</code> | If true the function will return object having result and dataVersion. |
160161

161162
**Example**
162163
```javascript
@@ -691,16 +692,17 @@ update the database details
691692
##### woqlClient.addDocument(json, [params], [dbId], [string], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
692693
to add a new document or a list of new documents into the instance or the schema graph.
693694
694-
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
695+
**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
696+
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
695697
696698
| Param | Type | Description |
697699
| --- | --- | --- |
698700
| json | <code>object</code> | |
699701
| [params] | <code>typedef.DocParamsPost</code> | the post parameters |
700702
| [dbId] | <code>string</code> | the dbid |
701703
| [string] | <code>message</code> | the insert commit message |
702-
| [lastDataVersion] | <code>string</code> | If passed it will be used for data version tracking. |
703-
| [getDataVersion] | <code>string</code> | If true it the function will return object having result and dataVersion. |
704+
| [lastDataVersion] | <code>string</code> | the last data version tracking id. |
705+
| [getDataVersion] | <code>boolean</code> | If true the function will return object having result and dataVersion. |
704706
705707
**Example**
706708
```javascript
@@ -718,43 +720,104 @@ const json = [{ "@type" : "Class",
718720
"perimeter" : { "@type" : "List",
719721
"@class" : "Coordinate" } }]
720722
client.addDocument(json,{"graph_type":"schema"},"mydb","add new schema")
723+
724+
725+
// Here we will pass true to show how to get dataVersion
726+
727+
const response = await client.addDocument(json, {"graph_type": "schema"},
728+
"mydb",
729+
"add new schema", '',
730+
true
731+
)
732+
console.log(response);
733+
734+
// This will output:
735+
// {
736+
// result: [ ...... ],
737+
// dataVersion: 'branch:5fs681tlycnn6jh0ceiqcq4qs89pdfs'
738+
// }
739+
740+
// Now we can use the data version we recieved as a response in previous
741+
// function call and used it is next function call as lastDataVersion
742+
743+
const response1 = await client.addDocument(json, {"graph_type": "schema"},
744+
"mydb",
745+
"add new schema", response.dataVersion,
746+
)
721747
```
722748
723749
## queryDocument
724750
##### woqlClient.queryDocument(query, [params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
725751
Retrieves all documents that match a given document template
726752
727-
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
753+
**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
754+
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
728755
729756
| Param | Type | Description |
730757
| --- | --- | --- |
731758
| query | <code>object</code> | the query template |
732759
| [params] | <code>typedef.DocParamsGet</code> | the get parameters |
733760
| [dbId] | <code>string</code> | the database id |
734761
| [branch] | <code>string</code> | the database branch |
735-
| [lastDataVersion] | <code>string</code> | If passed it will be used for data version tracking. |
736-
| [getDataVersion] | <code>string</code> | If true it the function will return object having result and dataVersion. |
762+
| [lastDataVersion] | <code>string</code> | the last data version tracking id. |
763+
| [getDataVersion] | <code>boolean</code> | If true the function will return object having result and dataVersion. |
737764
738765
**Example**
739766
```javascript
740767
const query = {
741768
"type": "Person",
742769
"query": { "age": 42 },
743770
}
744-
client.queryDocument(query,{"as_list":true})
771+
client.queryDocument(query, {"as_list":true})
772+
773+
774+
// Here we will pass true to show how to get dataVersion
775+
const query = {
776+
"type": "Person",
777+
"query": { "age": 42 },
778+
}
779+
780+
const response = await client.queryDocument(query, {"as_list": true}, '', '','',true);
781+
console.log(response);
782+
783+
// This will output:
784+
// {
785+
// result: [
786+
// {
787+
// '@id': 'Person/052d60ffbd114bf5e7331b03f07fcb7',
788+
// '@type': 'Person',
789+
// age: 42,
790+
// name: 'John',
791+
// },
792+
// ],
793+
// dataVersion: 'branch:5fs681tlycnn6jh0ceiqcq4qs89pdfs'
794+
// }
795+
796+
// Now we can use the data version we recieved as a response in previous
797+
// query and used it is next query as lastDataVersion
798+
const query = {
799+
"type": "Person",
800+
"query": { "age": 18 },
801+
}
802+
803+
const response1 = await client.queryDocument(query, {"as_list": true}, '',
804+
'',
805+
response.dataVersion
806+
);
745807
```
746808
747809
## getDocument
748810
##### woqlClient.getDocument([params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
749-
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
811+
**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
812+
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
750813
751814
| Param | Type | Description |
752815
| --- | --- | --- |
753816
| [params] | <code>typedef.DocParamsGet</code> | the get parameters |
754817
| [dbId] | <code>string</code> | the database id |
755818
| [branch] | <code>string</code> | the database branch |
756-
| [lastDataVersion] | <code>string</code> | If passed it will be used for data version tracking. |
757-
| [getDataVersion] | <code>string</code> | If true it the function will return object having result and dataVersion. |
819+
| [lastDataVersion] | <code>string</code> | the last data version tracking id. |
820+
| [getDataVersion] | <code>boolean</code> | If true the function will return object having result and dataVersion. |
758821
759822
**Example**
760823
```javascript
@@ -763,39 +826,152 @@ client.getDocument({"graph_type":"schema","as_list":true})
763826

764827
//retutn the Country class document from the schema graph
765828
client.getDocument({"graph_type":"schema","as_list":true,"id":"Country"})
829+
830+
831+
// Here we will pass true to show how to get dataVersion
832+
833+
const response = await client.getDocument({"graph_type":"schema","as_list":true},
834+
"",
835+
"",
836+
"",
837+
true
838+
)
839+
console.log(response);
840+
841+
// This will output:
842+
// {
843+
// result: [ ...... ],
844+
// dataVersion: 'branch:5fs681tlycnn6jh0ceiqcq4qs89pdfs'
845+
// }
846+
847+
// Now we can use the data version we recieved as a response in previous
848+
// function call and used it is next function call as lastDataVersion
849+
850+
const response1 = await client.getDocument({"graph_type":"schema","as_list":true},
851+
"",
852+
"",
853+
response.dataVersion,
854+
)
766855
```
767856
768857
## updateDocument
769858
##### woqlClient.updateDocument(json, [params], [dbId], [message], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
770-
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
859+
**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
860+
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
771861
772862
| Param | Type | Description |
773863
| --- | --- | --- |
774864
| json | <code>object</code> | |
775865
| [params] | <code>typedef.DocParamsPut</code> | the Put parameters |
776866
| [dbId] | <code>\*</code> | the database id |
777867
| [message] | <code>\*</code> | the update commit message |
778-
| [lastDataVersion] | <code>string</code> | If passed it will be used for data version tracking. |
779-
| [getDataVersion] | <code>string</code> | If true it the function will return object having result and dataVersion. |
868+
| [lastDataVersion] | <code>string</code> | the last data version tracking id. |
869+
| [getDataVersion] | <code>boolean</code> | If true the function will return object having result and dataVersion. |
780870
871+
**Example**
872+
```javascript
873+
client.updateDocument(
874+
{
875+
"@id": "Person",
876+
"@key": {
877+
"@type": "Random",
878+
},
879+
"@type": "Class",
880+
label: "xsd:string",
881+
},
882+
{ graph_type: "schema" }
883+
);
884+
885+
886+
// Here we will pass true to show how to get dataVersion
887+
888+
const response = await client.updateDocument(
889+
{
890+
"@id": "Person",
891+
"@key": {
892+
"@type": "Random",
893+
},
894+
"@type": "Class",
895+
label: "xsd:string",
896+
},
897+
{ graph_type: "schema" },
898+
"",
899+
"",
900+
"",
901+
true
902+
);
903+
console.log(response);
904+
905+
// This will output:
906+
// {
907+
// result: [ ...... ],
908+
// dataVersion: 'branch:5fs681tlycnn6jh0ceiqcq4qs89pdfs'
909+
// }
910+
911+
// Now we can use the data version we recieved as a response in previous
912+
// function call and used it is next function call as lastDataVersion
913+
914+
const response1 = await client.updateDocument(
915+
{
916+
"@id": "Person",
917+
"@key": {
918+
"@type": "Random",
919+
},
920+
"@type": "Class",
921+
label: "xsd:string",
922+
},
923+
{ graph_type: "schema" },
924+
"",
925+
"",
926+
response.dataVersion
927+
);
928+
```
781929
782930
## deleteDocument
783931
##### woqlClient.deleteDocument([params], [dbId], [message], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
784932
to delete the document
785933
786-
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
934+
**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
935+
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
787936
788937
| Param | Type | Description |
789938
| --- | --- | --- |
790939
| [params] | <code>typedef.DocParamsDelete</code> | |
791940
| [dbId] | <code>string</code> | the database id |
792941
| [message] | <code>string</code> | the delete message |
793-
| [lastDataVersion] | <code>string</code> | If passed it will be used for data version tracking |
794-
| [getDataVersion] | <code>string</code> | If true it the function will return object having result and dataVersion |
942+
| [lastDataVersion] | <code>string</code> | the last data version tracking id. |
943+
| [getDataVersion] | <code>boolean</code> | If true the function will return object having result and dataVersion. |
795944
796945
**Example**
797946
```javascript
798-
client.deleteDocument({"graph_type":"schema",id:['Country','Coordinate'])
947+
client.deleteDocument({"graph_type":"schema",id:['Country','Coordinate']})
948+
949+
950+
// Here we will pass true to show how to get dataVersion
951+
952+
const response = await client.deleteDocument({"graph_type":"schema",id:['Country','Coordinate']},
953+
"",
954+
"",
955+
"",
956+
true
957+
)
958+
console.log(response);
959+
960+
// This will output:
961+
// {
962+
// result: [ ...... ],
963+
// dataVersion: 'branch:5fs681tlycnn6jh0ceiqcq4qs89pdfs'
964+
// }
965+
966+
// Now we can use the data version we recieved as a response in previous
967+
// function call and used it is next function call as lastDataVersion
968+
969+
const response1 = await client.deleteDocument({"graph_type":"schema",
970+
id:['Country','Coordinate']},
971+
"",
972+
"",
973+
response.dataVersion,
974+
)
799975
```
800976
801977
## getSchemaFrame

0 commit comments

Comments
 (0)