Skip to content

database.dropTable()

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

DOCSAPIDatabase API


Programmatically perform a DROP TABLE operation.

See related ➞ DROP TABLE

Syntax

database.dropTable(
    name: string,
    options?: DropOptions
): Promise<DropTableResult>;
Param Interfaces Description
name - An existing table name.
options? DropOptions Optional extra parameters for the query.

DropOptions

type DropOptions = {
    ifExists?: boolean;
    cascade?: boolean;
    restrict?: boolean;
} & QueryOptions;
Param Interfaces Description
ifExists? - An optional flag that adds an EXISTS check to the operation. Defaults to false.
cascade? - (PostgreSQL) An optional flag that adds a CASCADE clause to the operation. Defaults to false.
restrict? - (PostgreSQL) An optional flag that adds a RESTRICT clause to the operation. Defaults to false.
Interface Description
QueryOptions Inherited options.

DropTableResult

type DropTableResult = boolean | TableSchema | Savepoint | null;
Type Interfaces Description
boolean - The boolean true—the default result type for DDL operations without a RETURNING clause.
TableSchema TableSchema For an operation with a RETURNING clause set to SCHEMA-the resulting database schema instance.
Savepoint | null Savepoint For an operation with a RETURNING clause set to SAVEPOINT-the Savepoint instance associated with the DDL operation; null when savepoint creation has been disabled at the server level.

Usage

See examples ➞ DROP TABLE

Basic call pattern

Drop a table:

await database.dropTable(
    'table_1',
    { desc: 'Drop description' }
);
Clone this wiki locally