-
-
Notifications
You must be signed in to change notification settings - Fork 2
client.createDatabase()
Oxford Harrison edited this page Nov 15, 2024
·
9 revisions
DOCS • API • Client API
Programmatically perform a CREATE DATABASE
operation.
See related ➞ CREATE DATABASE
client.createDatabase(
createSpec: string | DatabaseSchemaJson,
options?: CreateOptions
): Promise<CreateDatabaseResult>;
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. |
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. |
type CreateDatabaseResult = Database | DatabaseSchema | Savepoint | null;
Type | Interfaces | Description |
---|---|---|
Database |
Database |
For a CREATE operation without a RETURNING clause—an instance of Database on the just created object. |
DatabaseSchema |
DatabaseSchema |
For an operation with a RETURNING clause set to SCHEMA -the resulting database schema instance. |
Savepoint | null |
Savepoint |
For an operation with a RETURNING clause set to SAVEPOINT -the Savepoint instance associated with the DDL operation; null when savepoint creation has been disabled at the server level. |
See examples ➞ CREATE DATABASE
Specify database by name:
const database = await client.createDatabase(
'database_1',
{ desc: 'Create description' }
);
or by a schema object, optionally specifying a list of tables to create along with the database. (With each listed table corresponding to TableSchema
(in schema.json).):
const database = await client.createDatabase(
{
name: 'database_1',
tables: [{
name: 'table_1'
columns: [
{ name: 'column_1', type: 'int' },
{ name: 'column_2', type: 'time' }
]
}]
},
{ desc: 'Create description' }
);