-
-
Notifications
You must be signed in to change notification settings - Fork 2
database.createTable()
Oxford Harrison edited this page Nov 15, 2024
·
7 revisions
DOCS • API • Database API
Programmatically perform a CREATE TABLE
operation.
See related ➞ CREATE TABLE
database.createTable(
createSpec: string | TableSchemaJson,
options?: CreateOptions
): Promise<CreateTableResult>;
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. |
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 CreateTableResult = Table | TableSchema | Savepoint | null;
Type | Interfaces | Description |
---|---|---|
Table |
Table |
For a CREATE operation without a RETURNING clause—an instance of Table on the just created object. |
TableSchema |
TableSchema |
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 TABLE
Specify table by name:
const table = await database.createTable(
'table_1',
{ desc: 'Create description' }
);
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 table = await database.createTable(
{
name: 'table_1'
columns: [
{ name: 'column_1', type: 'int' },
{ name: 'column_2', type: 'time' }
]
},
{ desc: 'Create description' }
);