Skip to content

client.alterDatabase()

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

DOCSAPIClient API


Programmatically perform an ALTER DATABASE operation.

See also ➞ ALTER DATABASE

Syntax

client.alterDatabase(
    alterSpec: string | { name: string, tables?: string[] },
    callback: (databaseSchema: DatabaseSchemaAPI) => void,
    options?: AlterOptions
): Promise<DDLResult>;
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.
Interface Description
DDLResult The result type for DDL operations.

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.

Usage

Call patterns

Specify database by name:

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

or by an object, with an optional list of tables to be altered along with it:

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