Skip to content

database.dropTable()

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

Programmatically perform a DROP TABLE operation.

Syntax

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

DropOptions

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

Return Value

  • 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 table:

const savepoint = await database.dropTable(
    'table_1',
    { desc: 'Dropping for test purposes' }
);

Force-drop, if exits:

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