Skip to content
Oxford Harrison edited this page Nov 8, 2024 · 12 revisions

CREATE

Lang

const savepoint = await client.query(
    `CREATE DATABASE  database_1`
);

client.createDatabase():

Dynamically run a CREATE DATABASE operation.

client.createDatabase(databaseNameOrJson: string | DatabaseSchemaSpec, options?: Options): Promise<Savepoint>

Spec

  • databaseNameOrJson (string | DatabaseSchemaSpec): the database name, or an object specifying the intended database structure to create.
  • options (Options, optional): as described in query().
  • Return value: a Savepoint instance.

Usage

Specify database by name:

const savepoint = await client.createDatabase(
    'database_1',
    { desc: 'Just testing database creation' }
);

or by a schema object, with an optional list of tables to be created along with it. (Each listed table corresponding to TableSchemaSpec (in schema.json).):

const savepoint = await client.createDatabase(
    {
        name: 'database_1',
        tables: [{
            name: 'table_1'
            columns: [{ name: 'column_1', type: 'int' }, { name: 'column_2', type: 'time' }]
        }]
    },
    { desc: 'Just testing database creation' }
);

Some additional parameters via options:

  • ifNotExists (boolean, optional): a flag to conditionally create the database.

    const savepoint = await client.createDatabase('database_1', { ifNotExists: true, description: 'Just testing database creation' });
Clone this wiki locally