Skip to content

database.dropTable()

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

Programmatically perform a DROP TABLE operation.

Syntax

database.dropTable(
    name: string,
    options?: DropOptions
): Promise<Savepoint | boolean>;
Param Type Description
name string An existing table 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 table.
cascade boolean A flag to force-drop the table 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 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