method DatabaseSync.prototype.applyChangeset
#DatabaseSync.prototype.applyChangeset(changeset: Uint8Array,options?: ApplyChangesetOptions,): boolean
An exception is thrown if the database is not
open. This method is a wrapper around
sqlite3changeset_apply()
.
const sourceDb = new DatabaseSync(':memory:');
const targetDb = new DatabaseSync(':memory:');
sourceDb.exec('CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)');
targetDb.exec('CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)');
const session = sourceDb.createSession();
const insert = sourceDb.prepare('INSERT INTO data (key, value) VALUES (?, ?)');
insert.run(1, 'hello');
insert.run(2, 'world');
const changeset = session.changeset();
targetDb.applyChangeset(changeset);
// Now that the changeset has been applied, targetDb contains the same data as sourceDb.
Parameters #
#changeset: Uint8Array
A binary changeset or patchset.
#options: ApplyChangesetOptions
optional
The configuration options for how the changes will be applied.
Return Type #
boolean
Whether the changeset was applied succesfully without being aborted.