|
1 | 1 | import { AqlLiteral, AqlQuery, isAqlLiteral, isAqlQuery } from "./aql-query"; |
2 | | -import { ArangoCollection, constructCollection, DocumentCollection, EdgeCollection, isArangoCollection } from "./collection"; |
| 2 | +import { |
| 3 | + ArangoCollection, |
| 4 | + constructCollection, |
| 5 | + DocumentCollection, |
| 6 | + EdgeCollection, |
| 7 | + isArangoCollection |
| 8 | +} from "./collection"; |
3 | 9 | import { Config, Connection } from "./connection"; |
4 | 10 | import { ArrayCursor } from "./cursor"; |
5 | 11 | import { Graph } from "./graph"; |
6 | 12 | import { Route } from "./route"; |
7 | 13 | import { btoa } from "./util/btoa"; |
8 | 14 | import { toForm } from "./util/multipart"; |
9 | 15 |
|
10 | | - |
11 | 16 | function colToString(collection: string | ArangoCollection): string { |
12 | 17 | if (isArangoCollection(collection)) { |
13 | 18 | return String(collection.name); |
@@ -37,6 +42,7 @@ export type ServiceOptions = { |
37 | 42 | dependencies?: { [key: string]: any }; |
38 | 43 | }; |
39 | 44 |
|
| 45 | +const DATABASE_NOT_FOUND = 1228; |
40 | 46 | export class Database { |
41 | 47 | private _connection: Connection; |
42 | 48 |
|
@@ -91,6 +97,18 @@ export class Database { |
91 | 97 | ); |
92 | 98 | } |
93 | 99 |
|
| 100 | + exists(): Promise<boolean> { |
| 101 | + return this.get().then( |
| 102 | + () => true, |
| 103 | + err => { |
| 104 | + if (err.errorNum !== DATABASE_NOT_FOUND) { |
| 105 | + throw err; |
| 106 | + } |
| 107 | + return false; |
| 108 | + } |
| 109 | + ); |
| 110 | + } |
| 111 | + |
94 | 112 | createDatabase(databaseName: string, users?: string[]) { |
95 | 113 | return this._connection.request( |
96 | 114 | { |
@@ -687,7 +705,7 @@ export class Database { |
687 | 705 | ); |
688 | 706 | } |
689 | 707 |
|
690 | | - login(username: string = 'root', password: string = ''): Promise<string> { |
| 708 | + login(username: string = "root", password: string = ""): Promise<string> { |
691 | 709 | return this._connection.request( |
692 | 710 | { |
693 | 711 | method: "POST", |
|
0 commit comments