-
-
Notifications
You must be signed in to change notification settings - Fork 2
CREATE
Oxford Harrison edited this page Nov 8, 2024
·
12 revisions
const savepoint = await client.query(
`CREATE DATABASE database_1`
);
Dynamically run a CREATE DATABASE
operation.
client.createDatabase(databaseNameOrJson: string | DatabaseSchemaSpec, options?: Options): Promise<Savepoint>
-
databaseNameOrJson
(string |DatabaseSchemaSpec
): the database name, or an object specifying the intended database structure to create. -
options
(Options, optional): as described inquery()
. - Return value: a
Savepoint
instance.
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' });