Skip to content

Commit abdeb28

Browse files
authored
3.6 changes (#642)
1 parent 5bb147a commit abdeb28

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
@@ -195,6 +195,12 @@ export type CreateDatabaseUser = {
195195
extra?: { [key: string]: any };
196196
};
197197

198+
export type CreateDatabaseOptions = {
199+
sharding?: "" | "flexible" | "single";
200+
replicationFactor?: "satellite" | number;
201+
users?: CreateDatabaseUser[];
202+
};
203+
198204
export type VersionInfo = {
199205
server: string;
200206
license: "community" | "enterprise";
@@ -464,6 +470,7 @@ export class Database {
464470
//#endregion
465471

466472
//#region auth
473+
/** @deprecated Use "database" instead */
467474
useDatabase(databaseName: string): this {
468475
this._name = databaseName;
469476
return this;
@@ -524,13 +531,24 @@ export class Database {
524531

525532
createDatabase(
526533
databaseName: string,
527-
users?: CreateDatabaseUser[]
534+
options?: CreateDatabaseOptions
535+
): Promise<boolean>;
536+
createDatabase(
537+
databaseName: string,
538+
users: CreateDatabaseUser[]
539+
): Promise<boolean>;
540+
createDatabase(
541+
databaseName: string,
542+
usersOrOptions?: CreateDatabaseUser[] | CreateDatabaseOptions
528543
): Promise<boolean> {
544+
const options = Array.isArray(usersOrOptions)
545+
? { users: usersOrOptions }
546+
: usersOrOptions;
529547
return this.request(
530548
{
531549
method: "POST",
532550
path: "/_api/database",
533-
body: { users, name: databaseName }
551+
body: { ...options, name: databaseName }
534552
},
535553
res => res.body.result
536554
);

0 commit comments

Comments
 (0)