- 
          
- 
                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 EXISTScheck to the operation. Defaults to false. | 
| Interface | Description | 
|---|---|
| QueryOptions | Inherited options. | 
type CreateDatabaseResult = Database | DatabaseSchema | Savepoint | null;| Type | Interfaces | Description | 
|---|---|---|
| Database | Database | For a CREATEoperation without aRETURNINGclause—an instance ofDatabaseon the just created object. | 
| DatabaseSchema | DatabaseSchema | For an operation with a RETURNINGclause set toSCHEMA-the resulting database schema instance. | 
| Savepoint | null | Savepoint | For an operation with a RETURNINGclause set toSAVEPOINT-theSavepointinstance associated with the DDL operation;nullwhen 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' }
);