Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 35 additions & 12 deletions docs/Drivers/JS/Reference/Database/DatabaseManipulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,59 @@ const result = await db.exists();

## database.createDatabase

`async database.createDatabase(databaseName, options?): boolean`

`async database.createDatabase(databaseName, users?): boolean`

Creates a new database with the given _databaseName_ and optionally creates
the given _users_ for the new database.
Creates a new database with the given _databaseName_ with the given _options_.

**Arguments**

- **databaseName**: `string`

Name of the database to create.

- **users**: `Array<object>` (optional)
- **options**: `object` (optional)

An object with the following properties:

- **users**: `Array<object>` (optional)

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

- **username**: `string`

The username of the user to create for the database.

- **passwd**: `string` (Default: `""`)

The password of the user.

- **active**: `boolean` (Default: `true`)

Whether the user is active.

- **extra**: `object` (optional)

If specified, the array must contain objects with the following properties:
An object containing additional user data.

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

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

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

The password of the user.
One of `""`, `"flexible"` or `"single"`.

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

Whether the user is active.
Default replication factor for new collections in this database.

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

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

**Examples**

Expand Down
22 changes: 20 additions & 2 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ export type CreateDatabaseUser = {
extra?: { [key: string]: any };
};

export type CreateDatabaseOptions = {
sharding?: "" | "flexible" | "single";
replicationFactor?: "satellite" | number;
users?: CreateDatabaseUser[];
};

export type VersionInfo = {
server: string;
license: "community" | "enterprise";
Expand Down Expand Up @@ -464,6 +470,7 @@ export class Database {
//#endregion

//#region auth
/** @deprecated Use "database" instead */
useDatabase(databaseName: string): this {
this._name = databaseName;
return this;
Expand Down Expand Up @@ -524,13 +531,24 @@ export class Database {

createDatabase(
databaseName: string,
users?: CreateDatabaseUser[]
options?: CreateDatabaseOptions
): Promise<boolean>;
createDatabase(
databaseName: string,
users: CreateDatabaseUser[]
): Promise<boolean>;
createDatabase(
databaseName: string,
usersOrOptions?: CreateDatabaseUser[] | CreateDatabaseOptions
): Promise<boolean> {
const options = Array.isArray(usersOrOptions)
? { users: usersOrOptions }
: usersOrOptions;
return this.request(
{
method: "POST",
path: "/_api/database",
body: { users, name: databaseName }
body: { ...options, name: databaseName }
},
res => res.body.result
);
Expand Down