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

DocsDDLCREATECREATE DATABASE


Create empty database:

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

Note

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

client.createDatabase(..., { desc: 'Create description', kind: 'database' });

Create with an IF NOT EXISTS check:

// (a): SQL syntax
const savepoint = await client.query(
    `CREATE SCHEMA IF NOT EXISTS database_1`,
    { desc: 'Create description' }
);
// (b): Function-based syntax
const savepoint = await client.createDatabase(
    `database_1`,
    { desc: 'Create description', ifNotExists: true }
);

Create with tables:

// Function-based syntax
const savepoint = await client.createDatabase({
    name: 'database_1',
    tables: [{
        name: 'table_1',
        columns: []
    }, {
        name: 'table_2',
        columns: []
    }]
}, { desc: 'Create description' });
Clone this wiki locally