Skip to content

client.alterDatabase()

Oxford Harrison edited this page Nov 15, 2024 · 12 revisions

DOCSAPIClient API


Programmatically perform an ALTER DATABASE operation.

See related ➞ ALTER DATABASE

Syntax

client.alterDatabase(
    alterSpec: string | { name: string, tables?: string[] },
    callback: (databaseSchema: DatabaseSchemaAPI) => void,
    options?: AlterOptions
): Promise<AlterDatabaseResult>;
Param Interfaces Description
alterSpec - A database name, or an object specifying the name and, optionally, a list of tables to be included in the retrieved database schema instance.
callback DatabaseSchemaAPI A callback function that recieves the requested schema. This can be async.
options? AlterOptions Optional extra parameters for the query.

AlterOptions

type AlterOptions = {
    cascadeRule?: boolean;
    existsChecks?: boolean;
} & QueryOptions;
Param Interfaces Description
cascadeRule? - An optional flag that adds CASCADE flags to subtree manipulations. Defaults to false. (See ➞ ALTER DATABASE ➞ Managing Tables)
existsChecks? - An optional flag that adds EXISTS checks to subtree manipulations. Defaults to false. (See ➞ ALTER DATABASE ➞ Managing Tables)
Interface Description
QueryOptions Inherited options.

AlterDatabaseResult

type AlterDatabaseResult = Database | DatabaseSchema | Savepoint | null;
Type Interfaces Description
Database Database For a ALTER operation without a RETURNING clause—an instance of Database on the just altered object.
DatabaseSchema DatabaseSchema 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.

Usage

See examples ➞ ALTER DATABASE

Call patterns

Specify database by name:

// Change DB name
await client.alterDatabase(
    'database_1',
    (schema) => {
        schema.name('database_1_new');
    },
    { desc: 'Renaming for testing purposes' }
);

or by an object, with an optional list of tables to include in the returned schema (which defaults to all tables where not specified):

// Change DB name
await client.alterDatabase(
    { name: 'database_1', tables: ['table_1'] },
    (schema) => {
        schema.name('database_1_new');
        schema.table('table_1').name('table_1_new');
    }, 
    { desc: 'Renaming for testing purposes' }
);
Clone this wiki locally