Skip to content

client.createDatabase()

Oxford Harrison edited this page Nov 11, 2024 · 9 revisions

DOCSAPIClient API


Programmatically perform a CREATE DATABASE operation.

See ➞ CREATE DATABASE

Syntax

client.createDatabase(
    createSpec: string | DatabaseSchemaJson,
    options?: CreateOptions
): Promise<DDLResult>;
Param Interfaces Description
createSpec DatabaseSchemaJson A database name, or an object specifying the intended database structure to create.
options? CreateOptions Optional extra parameters for the query.
Interface Description
DDLResult The result type for DDL operations.

CreateOptions

type CreateOptions = {
    ifNotExists?: boolean;
} & QueryOptions;
Param Interfaces Description
ifNotExists? - An optional flag that adds an EXISTS check to the operation. Defaults to false.
Interface Description
QueryOptions Inherited options.

Usage

Call patterns

Specify database by name:

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

or by a schema object, optionally specifying a list of tables to create along with the database. (With each listed table corresponding to TableSchemaJson (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' }
);

Conditionally create using the options.ifNotExists parameter:

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