-
-
Couldn't load subscription status.
- Fork 2
database.createTable()
Oxford Harrison edited this page Nov 9, 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 | Type | Description |
|---|---|---|
createSpec |
string or TableSchemaJson
|
A table name, or an object specifying the intended table structure to create. |
options |
CreateOptions |
Extra parameters for the query—which extends standard QueryOptions. |
└ CreateOptions
| Param | Type | Applicable to | Description |
|---|---|---|---|
ifNotExists |
boolean | A flag to conditionally create the table. |
-
Savepoint | boolean: 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 }
);