File tree Expand file tree Collapse file tree 4 files changed +10641
-17436
lines changed Expand file tree Collapse file tree 4 files changed +10641
-17436
lines changed Original file line number Diff line number Diff line change @@ -338,6 +338,29 @@ name the databases list will be set to empty
338
338
client .organization (" admin" )
339
339
` ` `
340
340
341
+ ## hasDatabase
342
+ ##### woqlClient.hasDatabase([orgName], [dbName]) ⇒ <code>Promise</code>
343
+ Checks if a database exists
344
+
345
+ Returns true if a DB exists and false if it doesn't. Other results
346
+ throw an exception.
347
+
348
+
349
+ | Param | Type | Description |
350
+ | --- | --- | --- |
351
+ | [orgName] | <code>string</code> | the organization id to set the context to |
352
+ | [dbName] | <code>string</code> | the db name to set the context to |
353
+
354
+ **Example**
355
+ ` ` ` javascript
356
+ async function executeIfDatabaseExists (f ){
357
+ const hasDB = await client .hasDatabase (" admin" , " testdb" )
358
+ if (hasDB) {
359
+ f ()
360
+ }
361
+ }
362
+ ` ` `
363
+
341
364
## getDatabases
342
365
##### woqlClient.getDatabases() ⇒ <code>Promise</code>
343
366
Gets the organization's databases list.
Original file line number Diff line number Diff line change @@ -142,6 +142,37 @@ WOQLClient.prototype.organization = function (orgId) {
142
142
return this . connectionConfig . organization ( ) ;
143
143
} ;
144
144
145
+ /**
146
+ * Checks if a database exists
147
+ *
148
+ * Returns true if a DB exists and false if it doesn't. Other results
149
+ * throw an exception.
150
+ * @param {string } [orgName] the organization id to set the context to
151
+ * @param {string } [dbName] the db name to set the context to
152
+ * @returns {Promise }
153
+ * @example
154
+ * async function executeIfDatabaseExists(f){
155
+ * const hasDB = await client.hasDatabase("admin", "testdb")
156
+ * if (hasDB) {
157
+ * f()
158
+ * }
159
+ * }
160
+ */
161
+ WOQLClient . prototype . hasDatabase = async function ( orgName , dbName ) {
162
+ const dbCheckUrl = `${ this . connectionConfig . apiURL ( ) } db/${ orgName } /${ dbName } ` ;
163
+ return new Promise ( ( resolve , reject ) => {
164
+ this . dispatch ( CONST . HEAD , dbCheckUrl ) . then ( ( req ) => {
165
+ resolve ( true ) ;
166
+ } ) . catch ( ( err ) => {
167
+ if ( err . status === 404 ) {
168
+ resolve ( false ) ;
169
+ } else {
170
+ reject ( err ) ;
171
+ }
172
+ } ) ;
173
+ } ) ;
174
+ } ;
175
+
145
176
/**
146
177
* Gets the organization's databases list.
147
178
*
You can’t perform that action at this time.
0 commit comments