Skip to content
Oxford Harrison edited this page Nov 11, 2024 · 16 revisions

DocsDDLDropDrop Database


Drop database:

// (a): SQL syntax
const savepoint = await client.query(
    `DROP SCHEMA database_1`,
    { desc: 'Drop description' }
);
// (b): Function-based syntax
const savepoint = await client.dropDatabase(
    'database_1',
    { desc: 'Drop description' }
);

Note

While the function-based syntax may read "drop database", the "schema" kind is implied by default. To actually imply the "database" kind, set options.kind === 'database':

client.dropDatabase(..., { desc: 'Drop description', kind: 'database' });

Drop with an IF EXISTS check:

// (a): SQL syntax
const savepoint = await client.query(
    `DROP SCHEMA IF EXISTS database_1`,
    { desc: 'Drop description' }
);
// (b): Function-based syntax
const savepoint = await client.dropDatabase(
    'database_1',
    { desc: 'Drop description', ifExists: true }
);

Drop with a CASCADE or RESTRICT rule (PostgreSQL):

// (a): SQL syntax
const savepoint = await client.query(
    `DROP SCHEMA database_1 CASCADE`,
    { desc: 'Drop description' }
);
// (b): Function-based syntax
const savepoint = await client.dropDatabase(
    'database_1',
    { desc: 'Drop description', cascade: true }
);
Clone this wiki locally