arangodb / arangojs

The official ArangoDB JavaScript driver.
https://arangodb.github.io/arangojs
Apache License 2.0
600 stars 106 forks source link

Checking validity of connection to database #755

Closed gitgkk closed 2 years ago

gitgkk commented 2 years ago

There's no API that returns the validity of connection to database. https://arangodb.github.io/arangojs/latest/classes/_database_.database.html#name re new Database(config?: Config): Database new Database(url: string | string[], name?: undefined | string): Database useBasicAuth(username?: string, password?: string): this Usage example: const db = new Database({ url: "http://localhost:8529", databaseName: "my_database", auth: { username: "admin", password: "hunter2" }, }); all APIs return a database object but don't tell whether the connection was successful with given credentials or not.

So, how to check whether the program is connected to database successfully or not?

hesxenon commented 2 years ago

you could send a request to the REST api with db.request I guess. My best guess right now would be to use the _admin/status endpoint, so something like

const db = new Arango.Database(config);
const status$ = db.request({method: "GET", path: `_db/${db.name}/_api/_admin/status`}); // retry in .catch

That's how I do it, basically. Though it would be REALLY nice to have an api for this.

pluma commented 2 years ago

There's no way to know if the credentials and connection details are valid without talking to the database.

The canonical way to test if your settings are valid is to use await db.version().