-
-
Notifications
You must be signed in to change notification settings - Fork 2
client.createDatabase()
Oxford Harrison edited this page Nov 10, 2024
·
9 revisions
Programmatically perform a CREATE DATABASE
operation.
client.createDatabase(
createSpec: string | DatabaseSchemaJson,
options?: CreateOptions
): Promise<Savepoint | boolean>;
type CreateOptions {
[key: string]: any;
} & QueryOptions
Param | Description |
---|---|
createSpec |
A database name, or an object specifying the intended database structure to create. |
options |
Extra parameters for the query—which extends standard QueryOptions . |
└ CreateOptions
Param | Applicable to | Description |
---|---|---|
ifNotExists |
A flag to conditionally create the database. |
- A Savepoint instance (See ➞
Savepoint
) or the booleantrue
when savepoint creation has been disabled viaoptions.noCreateSavepoint
; (Compare ➞ Query Return Value)
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 }
);