- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2
DROP DATABASE
        Oxford Harrison edited this page Nov 15, 2024 
        ·
        16 revisions
      
    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' });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 }
);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 }
);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()