Skip to content

client.dropDatabase()

Oxford Harrison edited this page Nov 9, 2024 · 5 revisions

Programmatically perform a DROP DATABASE operation.

Syntax

client.dropDatabase(
    name: string,
    options?: DropOptions
): Promise<Savepoint | boolean>;
Param Type Description
name string An existing database name.
options DropOptions Extra parameters for the query—which extends standard QueryOptions.

DropOptions

Param Type Applicable to Description
ifExists boolean A flag to conditionally drop the database.
cascade boolean A flag to force-drop the database along with its dependent objects.

Return Value

  • Savepoint | boolean: a Savepoint instance (See ➞ Savepoint) or the boolean true when savepoint creation has been disabled via options.noCreateSavepoint; (Compare ➞ Query Return Value)

Usage

Drop a database:

const savepoint = await client.dropDatabase(
    'database_1',
    { desc: 'Dropping for test purposes' }
);

Force-drop, if exits:

const savepoint = await client.dropDatabase(
    'database_1',
    { desc: 'Dropping for test purposes', ifExists: true, cascade: true }
);
Clone this wiki locally