Skip to content

savepoint.recommit()

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

DOCSAPISavepoint API


Perform a recommit.

See related ➞ savepoint.rollback()

Syntax

savepoint.recommit(
    options?: RecommitOptions
): Promise<boolean>;
Param Interfaces Description
options? RecommitOptions Optional extra parameters for the operation.

RecommitOptions

type RecommitOptions = {
    desc?: string;
};
Param Interfaces Description
desc? - An optional string description of the commit operation. Required if the Linked DB's config.require_commit_descs is active.

Usage

Create savepoints:

// Perform a DDL operation and obtain savepoint (1)
const savepoint1 = await client.createDatabase(
    {
        name: 'database_1',
        tables: [{
            name: 'table_1',
            columns: [],
        }]
    },
    { desc: 'Create description', returning: 'savepoint' }
);
// Perform a DDL operation and obtain savepoint (2)
const savepoint2 = await client.database('database_1').createTable(
    {
        name: 'table_2',
        columns: [],
    },
    { desc: 'Create description', returning: 'savepoint' }
);

Rollback all changes (latest-first):

// Rollback to version 1 (drops table)
await savepoint2.rollback({
    desc: 'Changes no more necessary'
});
// Rollback to version 0 (drops database)
await savepoint1.rollback({
    desc: 'Changes no more necessary'
});

Recommit all changes (oldest-first):

// Rollback to version 1 (recreates database)
await savepoint1.recommit({
    desc: 'Changes necessary again'
});
// Rollback to version 0 (recreates table)
await savepoint2.recommit({
    desc: 'Changes necessary again'
});
Clone this wiki locally