-
-
Notifications
You must be signed in to change notification settings - Fork 2
database.createTable()
Oxford Harrison edited this page Nov 10, 2024
·
7 revisions
Programmatically perform a CREATE TABLE operation.
database.createTable(
createSpec: string | TableSchemaJson,
options?: CreateOptions
): Promise<Savepoint | boolean>;type CreateOptions {
[key: string]: any;
} & QueryOptions| Param | Description |
|---|---|
createSpec |
A table name, or an object specifying the intended table 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 table. |
- A Savepoint instance (See ➞
Savepoint) or the booleantruewhen savepoint creation has been disabled viaoptions.noCreateSavepoint; (Compare ➞ Query Return Value)
Specify table by name:
const savepoint = await database.createTable(
'table_1',
{ desc: 'Just testing table creation' }
);or by a schema object, optionally specifying a list of tables to create along with the table. (With each listed table corresponding to TableSchemaJson (in schema.json).):
const savepoint = await database.createTable(
{
name: 'table_1'
columns: [
{ name: 'column_1', type: 'int' },
{ name: 'column_2', type: 'time' }
]
},
{ desc: 'Just testing table creation' }
);Conditionally create using the options.ifNotExists parameter:
const savepoint = await database.createTable(
'table_1',
{ desc: 'Just testing table creation', ifNotExists: true }
);