-
-
Notifications
You must be signed in to change notification settings - Fork 2
database.alterTable()
Oxford Harrison edited this page Nov 15, 2024
·
7 revisions
DOCS • API • Database API
Programmatically perform an ALTER TABLE
operation.
See related ➞ ALTER TABLE
database.alterTable(
alterSpec: string,
callback: (tableSchema: TableSchema) => void,
options?: AlterOptions
): Promise<AlterTableResult>;
Param | Interfaces | Description |
---|---|---|
alterSpec |
- | A table name. |
callback |
TableSchema | A callback function that recieves the requested schema. This can be async. |
options? |
AlterOptions |
Optional extra parameters for the query. |
type AlterOptions = {
cascadeRule?: boolean;
existsChecks?: boolean;
} & QueryOptions;
Param | Interfaces | Description |
---|---|---|
cascadeRule |
- | A flag that adds CASCADE flags to subtree manipulations. Defaults to false. (See ➞ ALTER TABLE ➞ Managing Columns)
|
existsChecks |
- | A flag that adds EXISTS checks to subtree manipulations. Defaults to false. (See ➞ ALTER TABLE ➞ Managing columns)
|
Interface | Description |
---|---|
QueryOptions | Inherited options. |
type AlterTableResult = Table | TableSchema | Savepoint | null;
Type | Interfaces | Description |
---|---|---|
Table |
Table |
For an ALTER 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 ➞ ALTER TABLE
Change table name:
// Change table name
await database.alterTable(
'table_1',
(schema) => {
schema.name('table_1_new');
},
{ desc: 'Alter description' }
);