Skip to content

Commit 966b44e

Browse files
Kitty JoseKitty Jose
authored andcommitted
2 parents e599c7c + 57c3048 commit 966b44e

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

docs/api/woqlclient.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,10 @@ const response1 = await client.addDocument(json, {"graph_type": "schema"},
748748
```
749749
750750
## queryDocument
751-
##### woqlClient.queryDocument(query, [params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
752-
Retrieves all documents that match a given document template
751+
##### ~~woqlClient.queryDocument(query, [params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>~~
752+
***Deprecated***
753+
754+
Use [#getDocument](#getDocument) instead.
753755
754756
**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
755757
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
@@ -808,7 +810,7 @@ console.log(response);
808810
```
809811
810812
## getDocument
811-
##### woqlClient.getDocument([params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
813+
##### woqlClient.getDocument([params], [dbId], [branch], [lastDataVersion], [getDataVersion], [query]) ⇒ <code>Promise</code>
812814
**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
813815
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
814816
@@ -819,6 +821,7 @@ and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error
819821
| [branch] | <code>string</code> | the database branch |
820822
| [lastDataVersion] | <code>string</code> | the last data version tracking id. |
821823
| [getDataVersion] | <code>boolean</code> | If true the function will return object having result and dataVersion. |
824+
| [query] | <code>object</code> | If a query object is provided, the function will use it to query the database. |
822825
823826
**Example**
824827
```javascript
@@ -856,7 +859,7 @@ const response1 = await client.getDocument({"graph_type":"schema","as_list":true
856859
```
857860
858861
## updateDocument
859-
##### woqlClient.updateDocument(json, [params], [dbId], [message], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
862+
##### woqlClient.updateDocument(json, [params], [dbId], [message], [lastDataVersion], [getDataVersion], [create]) ⇒ <code>Promise</code>
860863
**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
861864
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
862865
@@ -868,6 +871,7 @@ and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error
868871
| [message] | <code>\*</code> | the update commit message |
869872
| [lastDataVersion] | <code>string</code> | the last data version tracking id. |
870873
| [getDataVersion] | <code>boolean</code> | If true the function will return object having result and dataVersion. |
874+
| [create] | <code>boolean</code> | If true, the function will create a new document if it doesn't exist. |
871875
872876
**Example**
873877
```javascript

lib/query/woqlDoc.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function convert(obj) {
4040
'@type': 'Value',
4141
variable: obj.name,
4242
};
43-
} if (typeof (obj) === 'object') {
43+
} if (typeof (obj) === 'object' && !Array.isArray(obj)) {
4444
const pairs = [];
4545
// eslint-disable-next-line no-restricted-syntax
4646
for (const [key, value] of Object.entries(obj)) {
@@ -57,6 +57,12 @@ function convert(obj) {
5757
data: pairs,
5858
},
5959
};
60+
} if (typeof (obj) === 'object' && Array.isArray(obj)) {
61+
const list = obj.map(convert);
62+
return {
63+
'@type': 'Value',
64+
list,
65+
};
6066
}
6167
}
6268

lib/woqlClient.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,9 @@ WOQLClient.prototype.addDocument = function (json, params, dbId, message = 'add
10121012
};
10131013

10141014
/**
1015+
* Use {@link #getDocument} instead.
1016+
* @deprecated
1017+
*
10151018
* Retrieves all documents that match a given document template
10161019
* @param {object} query - the query template
10171020
* @param {typedef.DocParamsGet} [params] - the get parameters
@@ -1092,6 +1095,8 @@ WOQLClient.prototype.queryDocument = function (query, params, dbId, branch, last
10921095
* @param {string} [lastDataVersion] the last data version tracking id.
10931096
* @param {boolean} [getDataVersion] If true the function will return object having result
10941097
* and dataVersion.
1098+
* @param {object} [query] If a query object is provided, the function will use it to
1099+
* query the database.
10951100
* @returns {Promise} A promise that returns the call response object or object having *result*
10961101
* and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
10971102
* @example
@@ -1128,7 +1133,7 @@ WOQLClient.prototype.queryDocument = function (query, params, dbId, branch, last
11281133
* )
11291134
*/
11301135
// document interface
1131-
WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersion = '', getDataVersion = false) {
1136+
WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersion = '', getDataVersion = false, query = undefined) {
11321137
if (dbId) {
11331138
this.db(dbId);
11341139
}
@@ -1138,6 +1143,16 @@ WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersi
11381143
if (typeof lastDataVersion === 'string' && lastDataVersion !== '') {
11391144
this.customHeaders({ 'TerminusDB-Data-Version': lastDataVersion });
11401145
}
1146+
1147+
if (query) {
1148+
return this.dispatch(
1149+
CONST.QUERY_DOCUMENT,
1150+
this.connectionConfig.documentURL(params),
1151+
query,
1152+
getDataVersion,
1153+
);
1154+
}
1155+
11411156
return this.dispatch(CONST.GET, this.connectionConfig.documentURL(params), {}, getDataVersion);
11421157
};
11431158

@@ -1150,6 +1165,7 @@ WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersi
11501165
* @param {string} [lastDataVersion] the last data version tracking id.
11511166
* @param {boolean} [getDataVersion] If true the function will return object having result
11521167
* and dataVersion.
1168+
* @param {boolean} [create] If true, the function will create a new document if it doesn't exist.
11531169
* @returns {Promise} A promise that returns the call response object or object having *result*
11541170
* and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
11551171
* @example
@@ -1210,10 +1226,11 @@ WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersi
12101226
);
12111227
*/
12121228

1213-
WOQLClient.prototype.updateDocument = function (json, params, dbId, message = 'update document', lastDataVersion = '', getDataVersion = false, compress = false) {
1229+
WOQLClient.prototype.updateDocument = function (json, params, dbId, message = 'update document', lastDataVersion = '', getDataVersion = false, compress = false, create = false) {
12141230
const docParams = params || {};
12151231
docParams.author = this.author();
12161232
docParams.message = message;
1233+
docParams.create = create;
12171234
if (dbId) {
12181235
this.db(dbId);
12191236
}

0 commit comments

Comments
 (0)