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

DOCSLANGDROP


See APIS ➞ client.query(), client.dropDatabase()

Drop database:

// (a): SQL syntax
await client.query(
    `DROP SCHEMA database_1`,
    { desc: 'Drop description' }
);
// (b): Function-based syntax
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' });

The IF EXISTS clause

Drop with an EXISTS check:

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

The CASCADE|RESTRICT clause

Drop with a CASCADE or RESTRICT rule (PostgreSQL):

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

The RETURNING clause

Return the dropped database schema:

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

See related ➞ database.schema()

Return the associated savepoint instance:

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

See related ➞ database.savepoint()

Clone this wiki locally