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

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 that while the function-based syntax may read "drop database", the "schema" type is implied by default.

Drop conditionally:

// (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 (postgres):

// (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