-
-
Couldn't load subscription status.
- Fork 2
database.createTable()
Oxford Harrison edited this page Nov 11, 2024
·
7 revisions
DOCS • API • Database API
Programmatically perform a CREATE TABLE operation.
See ➞ CREATE TABLE
database.createTable(
createSpec: string | TableSchemaJson,
options?: CreateOptions
): Promise<DDLResult>;| Param | Interfaces | Description |
|---|---|---|
createSpec |
TableSchemaJson |
A table name, or an object specifying the intended table structure to create. |
options? |
CreateOptions |
Optional extra parameters for the query. |
| Interface | Description |
|---|---|
| DDLResult | The result type for DDL operations. |
type CreateOptions = {
ifNotExists?: boolean;
} & QueryOptions;| Param | Interfaces | Description |
|---|---|---|
ifNotExists |
- | A flag that adds an EXISTS check to the operation. Defaults to false. |
| Interface | Description |
|---|---|
| QueryOptions | Inherited options. |
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 }
);