Skip to content

savepoint.versionState()

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

DOCSAPISavepoint API


Get the Savepoint's version state.

Syntax

savepoint.versionState(): string;

Usage

Savepoints are in the commit state by default:

// initial creation
const savepoint = await client.createDatabase(
    {
        name: 'database_1',
        tables: [{
            name: 'table_1',
            columns: [],
        }]
    },
    { desc: 'Create description', returning: 'savepoint' }
);
console.log(savepoint.versionState()); // "commit"

A rollback sets them to the rollback state:

// Rollback to version 0
await savepoint.rollback({
    desc: 'Changes no more necessary'
});
console.log(savepoint.versionState()); // "rollback"
// Version 0 currently
const savepoint = await client.database('database_1').savepoint({ lookAhead: true });
console.log(savepoint.versionState()); // "rollback"

A recommit (i.e. rollforward) sets them back to the commit state:

// Rollforward to version 1
await savepoint.recommit({
    desc: 'Changes necessary again'
});
console.log(savepoint.versionState()); // "commit"
// Version 1 currently
const savepoint = await client.database('database_1').savepoint();
console.log(savepoint.versionState()); // "commit"
Clone this wiki locally