Skip to content

Commit bf1a512

Browse files
committed
Add database.version and .login to reference
1 parent 745fe16 commit bf1a512

File tree

2 files changed

+57
-21
lines changed

2 files changed

+57
-21
lines changed

docs/Drivers/JS/Reference/Database/DatabaseManipulation.md

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ _databaseName_, then returns itself.
2424

2525
**Arguments**
2626

27-
* **databaseName**: `string`
27+
- **databaseName**: `string`
2828

2929
The name of the database to use.
3030

@@ -38,18 +38,18 @@ db.useDatabase("test");
3838

3939
## database.useBasicAuth
4040

41-
`database.useBasicAuth(username, password): this`
41+
`database.useBasicAuth([username, [password]]): this`
4242

4343
Updates the _Database_ instance's `authorization` header to use Basic
4444
authentication with the given _username_ and _password_, then returns itself.
4545

4646
**Arguments**
4747

48-
* **username**: `string` (Default: `"root"`)
48+
- **username**: `string` (Default: `"root"`)
4949

5050
The username to authenticate with.
5151

52-
* **password**: `string` (Default: `""`)
52+
- **password**: `string` (Default: `""`)
5353

5454
The password to authenticate with.
5555

@@ -72,7 +72,7 @@ authentication with the given authentication token, then returns itself.
7272

7373
**Arguments**
7474

75-
* **token**: `string`
75+
- **token**: `string`
7676

7777
The token to authenticate with.
7878

@@ -84,6 +84,48 @@ db.useBearerAuth("keyboardcat");
8484
// The database instance now uses Bearer authentication.
8585
```
8686

87+
## database.login
88+
89+
`async database.login([username, [password]]): this`
90+
91+
Validates the given database credentials and exchanges them for an
92+
authentication token, then uses the authentication token for future
93+
requests.
94+
95+
**Arguments**
96+
97+
- **username**: `string` (Default: `"root"`)
98+
99+
The username to authenticate with.
100+
101+
- **password**: `string` (Default: `""`)
102+
103+
The password to authenticate with.
104+
105+
**Examples**
106+
107+
```js
108+
const db = new Database();
109+
db.useDatabase("test");
110+
await db.login("admin", "hunter2");
111+
// The database instance now uses the database "test"
112+
// with an authentication token for the "admin" user.
113+
```
114+
115+
## database.version
116+
117+
`async database.version(): Object`
118+
119+
Fetches the ArangoDB version information for the active database from the server.
120+
121+
**Examples**
122+
123+
```js
124+
const db = new Database();
125+
const version = await db.version();
126+
// the version object contains the ArangoDB version information.
127+
```
128+
87129
## database.createDatabase
88130

89131
`async database.createDatabase(databaseName, [users]): Object`
@@ -92,27 +134,27 @@ Creates a new database with the given _databaseName_.
92134

93135
**Arguments**
94136

95-
* **databaseName**: `string`
137+
- **databaseName**: `string`
96138

97139
Name of the database to create.
98140

99-
* **users**: `Array<Object>` (optional)
141+
- **users**: `Array<Object>` (optional)
100142

101143
If specified, the array must contain objects with the following properties:
102144

103-
* **username**: `string`
145+
- **username**: `string`
104146

105147
The username of the user to create for the database.
106148

107-
* **passwd**: `string` (Default: empty)
149+
- **passwd**: `string` (Default: empty)
108150

109151
The password of the user.
110152

111-
* **active**: `boolean` (Default: `true`)
153+
- **active**: `boolean` (Default: `true`)
112154

113155
Whether the user is active.
114156

115-
* **extra**: `Object` (optional)
157+
- **extra**: `Object` (optional)
116158

117159
An object containing additional user data.
118160

@@ -187,7 +229,7 @@ Deletes **all documents in all collections** in the active database.
187229

188230
**Arguments**
189231

190-
* **excludeSystem**: `boolean` (Default: `true`)
232+
- **excludeSystem**: `boolean` (Default: `true`)
191233

192234
Whether system collections should be excluded. Note that this option will be
193235
ignored because truncating system collections is not supported anymore for

src/database.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import { AqlLiteral, AqlQuery, isAqlLiteral, isAqlQuery } from "./aql-query";
2-
import {
3-
ArangoCollection,
4-
DocumentCollection,
5-
EdgeCollection,
6-
constructCollection,
7-
isArangoCollection
8-
} from "./collection";
2+
import { ArangoCollection, constructCollection, DocumentCollection, EdgeCollection, isArangoCollection } from "./collection";
93
import { Config, Connection } from "./connection";
10-
114
import { ArrayCursor } from "./cursor";
125
import { Graph } from "./graph";
136
import { Route } from "./route";
147
import { btoa } from "./util/btoa";
158
import { toForm } from "./util/multipart";
169

10+
1711
function colToString(collection: string | ArangoCollection): string {
1812
if (isArangoCollection(collection)) {
1913
return String(collection.name);
@@ -693,7 +687,7 @@ export class Database {
693687
);
694688
}
695689

696-
login(username: string, password: string): Promise<string> {
690+
login(username: string = 'root', password: string = ''): Promise<string> {
697691
return this._connection.request(
698692
{
699693
method: "POST",

0 commit comments

Comments
 (0)