sqlite3orm
Version:
ORM for sqlite3 and TypeScript/JavaScript
84 lines • 2.5 kB
JavaScript
/* eslint-disable @typescript-eslint/no-explicit-any */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SqlBackup = void 0;
const tslib_1 = require("tslib");
// online backup
const _dbg = tslib_1.__importStar(require("debug"));
const debug = _dbg.default('sqlite3orm:backup');
class SqlBackup {
// TODO(Backup API): typings not yet available
// https://github.com/TryGhost/node-sqlite3/pull/1726
// https://github.com/TryGhost/node-sqlite3/pull/1116
backup;
get idle() {
return this.backup.idle;
}
get completed() {
return this.backup.completed;
}
get failed() {
return this.backup.failed;
}
/**
* Returns an integer with the remaining number of pages left to copy
* Returns -1 if `step` not yet called
*/
get remaining() {
return this.backup.remaining;
}
/**
* Returns an integer with the total number of pages
* Returns -1 if `step` not yet called
*/
get pageCount() {
return this.backup.pageCount;
}
/**
* Returns the progress (percentage completion)
*/
get progress() {
const pageCount = this.pageCount;
const remaining = this.remaining;
if (pageCount === -1 || remaining === -1) {
return 0;
}
return pageCount === 0 ? 100 : ((pageCount - remaining) / pageCount) * 100;
}
/**
* Creates an instance of SqlBackup.
*
* @param backup
*/
constructor(backup) {
this.backup = backup;
debug(`backup initialized: page count: ${this.pageCount}`);
}
step(pages = -1) {
return new Promise((resolve, reject) => {
/* istanbul ignore if */
if (!this.backup) {
const err = new Error('backup handle not open');
debug(`step '${pages}' failed: ${err.message}`);
reject(err);
return;
}
this.backup.step(pages, (err) => {
/* istanbul ignore if */
if (err) {
debug(`step '${pages}' failed: ${err.message}`);
reject(err);
return;
}
debug(`step '${pages}' succeeded`);
resolve();
});
});
}
finish() {
debug(`finished`);
this.backup.finish();
}
}
exports.SqlBackup = SqlBackup;
//# sourceMappingURL=SqlBackup.js.map
;