Skip to content

Commit 55d90a7

Browse files
authored
Fix for updateDatabase (issue #246) (#247)
The client incorrectly used the createDatabase stub and used POST instead of PUT to update the data product details. Client is updated with a separate implementation of updateDatabase. Co-authored-by: hoijnet <hoijnet@users.noreply.github.com>
1 parent 713d8cc commit 55d90a7

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

docs/api/woqlclient.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,23 @@ of the current context for "commits" "meta" "branch" and "ref" special resources
550550
const branch_resource = client.resource("branch")
551551
```
552552
553+
## module_WOQLClient..WOQLClient+updateDatabase
554+
##### woqlClient.updateDatabase(dbId, dbDetails, [orgId]) ⇒ <code>Promise</code>
555+
Update a database in TerminusDB server
556+
557+
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
558+
559+
| Param | Type | Description |
560+
| --- | --- | --- |
561+
| dbId | <code>string</code> | The id of the database to be updated |
562+
| dbDetails | <code>typedef.DbDetails</code> | object containing details about the database to be updated |
563+
| [orgId] | <code>string</code> | optional organization id - if absent default local organization id is used |
564+
565+
**Example**
566+
```javascript
567+
client.updateDatabase({id: "mydb", label: "My Database", comment: "Testing"})
568+
```
569+
553570
## module_WOQLClient..WOQLClient+insertTriples
554571
##### woqlClient.insertTriples(graphType, turtle, commitMsg) ⇒ <code>Promise</code>
555572
Appends the passed turtle to the contents of a graph
@@ -702,17 +719,6 @@ Adds an author string (from the user object returned by connect) to the commit m
702719
| [rc_args] | <code>object</code> |
703720
704721
705-
## module_WOQLClient..WOQLClient+updateDatabase
706-
##### woqlClient.updateDatabase(dbDoc) ⇒ <code>Promise</code>
707-
update the database details
708-
709-
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
710-
711-
| Param | Type | Description |
712-
| --- | --- | --- |
713-
| dbDoc | <code>object</code> | an object that describe the database details |
714-
715-
716722
## module_WOQLClient..WOQLClient+addDocument
717723
##### woqlClient.addDocument(json, [params], [dbId], [string], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
718724
to add a new document or a list of new documents into the instance or the schema graph.

lib/woqlClient.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,29 @@ WOQLClient.prototype.createDatabase = function (dbId, dbDetails, orgId) {
458458
);
459459
};
460460

461+
/**
462+
* Update a database in TerminusDB server
463+
* @param {string} dbId - The id of the database to be updated
464+
* @param {typedef.DbDetails} dbDetails - object containing details about the database to be updated
465+
* @param {string} [orgId] - optional organization id - if absent default local organization
466+
* id is used
467+
* @returns {Promise} A promise that returns the call response object, or an Error if rejected.
468+
* @example
469+
* client.updateDatabase({id: "mydb", label: "My Database", comment: "Testing"})
470+
*/
471+
WOQLClient.prototype.updateDatabase = function (dbDoc) {
472+
const dbid = dbDoc.id || this.db();
473+
this.organization(dbDoc.organization || this.organization());
474+
if (dbid) {
475+
this.db(dbid);
476+
return this.dispatch(CONST.PUT, this.connectionConfig.dbURL(), dbDoc);
477+
}
478+
const errmsg = `Update database error - you must specify a valid database id - ${dbid} is invalid`;
479+
return Promise.reject(
480+
new Error(ErrorMessage.getInvalidParameterMessage(CONST.UPDATE_DATABASE, errmsg)),
481+
);
482+
};
483+
461484
/**
462485
* Deletes a database from a TerminusDB server
463486
* @param {string} dbId The id of the database to be deleted
@@ -966,17 +989,6 @@ WOQLClient.prototype.prepareRevisionControlArgs = function (rc_args) {
966989
return rc_args;
967990
};
968991

969-
/**
970-
* update the database details
971-
* @param {object} dbDoc - an object that describe the database details
972-
* @returns {Promise} A promise that returns the call response object, or an Error if rejected.
973-
*/
974-
WOQLClient.prototype.updateDatabase = function (dbDoc) {
975-
const dbid = dbDoc.id || this.db();
976-
const org = dbDoc.organization || this.organization();
977-
return this.createDatabase(dbid, dbDoc, org);
978-
};
979-
980992
/**
981993
* to add a new document or a list of new documents into the instance or the schema graph.
982994
* @param {object} json

0 commit comments

Comments
 (0)