Skip to content

Commit 32d1ee9

Browse files
committed
3.6 changes (#642)
1 parent 1899932 commit 32d1ee9

File tree

2 files changed

+55
-14
lines changed

2 files changed

+55
-14
lines changed

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

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,59 @@ const result = await db.exists();
3333

3434
## database.createDatabase
3535

36+
`async database.createDatabase(databaseName, options?): boolean`
37+
3638
`async database.createDatabase(databaseName, users?): boolean`
3739

38-
Creates a new database with the given _databaseName_ and optionally creates
39-
the given _users_ for the new database.
40+
Creates a new database with the given _databaseName_ with the given _options_.
4041

4142
**Arguments**
4243

4344
- **databaseName**: `string`
4445

4546
Name of the database to create.
4647

47-
- **users**: `Array<object>` (optional)
48+
- **options**: `object` (optional)
49+
50+
An object with the following properties:
51+
52+
- **users**: `Array<object>` (optional)
53+
54+
If specified, the array must contain objects with the following properties:
55+
56+
- **username**: `string`
57+
58+
The username of the user to create for the database.
59+
60+
- **passwd**: `string` (Default: `""`)
61+
62+
The password of the user.
63+
64+
- **active**: `boolean` (Default: `true`)
65+
66+
Whether the user is active.
67+
68+
- **extra**: `object` (optional)
4869

49-
If specified, the array must contain objects with the following properties:
70+
An object containing additional user data.
5071

51-
- **username**: `string`
72+
If ArangoDB is running in a cluster configuration, the object has the
73+
following additional properties:
5274

53-
The username of the user to create for the database.
75+
- **sharding**: `string` (optional)
5476

55-
- **passwd**: `string` (Default: `""`)
77+
The sharding method to use for new collections in this database.
5678

57-
The password of the user.
79+
One of `""`, `"flexible"` or `"single"`.
5880

59-
- **active**: `boolean` (Default: `true`)
81+
- **replicationFactor**: `number | "satellite"` (optional)
6082

61-
Whether the user is active.
83+
Default replication factor for new collections in this database.
6284

63-
- **extra**: `object` (optional)
85+
Setting this to `1` disables replication. Setting this to `"satellite"`
86+
will replicate to every DBServer.
6487

65-
An object containing additional user data.
88+
If _options_ is an array, it will be interpreted as _options.users_.
6689

6790
**Examples**
6891

src/database.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ export type CreateDatabaseUser = {
201201
extra?: { [key: string]: any };
202202
};
203203

204+
export type CreateDatabaseOptions = {
205+
sharding?: "" | "flexible" | "single";
206+
replicationFactor?: "satellite" | number;
207+
users?: CreateDatabaseUser[];
208+
};
209+
204210
export type VersionInfo = {
205211
server: string;
206212
license: "community" | "enterprise";
@@ -470,6 +476,7 @@ export class Database {
470476
//#endregion
471477

472478
//#region auth
479+
/** @deprecated Use "database" instead */
473480
useDatabase(databaseName: string): this {
474481
this._name = databaseName;
475482
return this;
@@ -530,13 +537,24 @@ export class Database {
530537

531538
createDatabase(
532539
databaseName: string,
533-
users?: CreateDatabaseUser[]
540+
options?: CreateDatabaseOptions
541+
): Promise<boolean>;
542+
createDatabase(
543+
databaseName: string,
544+
users: CreateDatabaseUser[]
545+
): Promise<boolean>;
546+
createDatabase(
547+
databaseName: string,
548+
usersOrOptions?: CreateDatabaseUser[] | CreateDatabaseOptions
534549
): Promise<boolean> {
550+
const options = Array.isArray(usersOrOptions)
551+
? { users: usersOrOptions }
552+
: usersOrOptions;
535553
return this.request(
536554
{
537555
method: "POST",
538556
path: "/_api/database",
539-
body: { users, name: databaseName }
557+
body: { ...options, name: databaseName }
540558
},
541559
res => res.body.result
542560
);

0 commit comments

Comments
 (0)