Export rename(base, file) on BaseDb
This commit is contained in:
@@ -29,6 +29,8 @@ const l = logger('db/flat');
|
||||
export default class FileFlatDb implements BaseDb {
|
||||
private _fd: number;
|
||||
private _fileSize: number = 0;
|
||||
private _base: string;
|
||||
private _path: string;
|
||||
private _file: string;
|
||||
private _isCompressed: boolean;
|
||||
private _lruBranch: LRUMap<number, Buffer>;
|
||||
@@ -36,7 +38,9 @@ export default class FileFlatDb implements BaseDb {
|
||||
|
||||
constructor (base: string, file: string = defaults.DEFAULT_FILE, options: BaseDbOptions = {}) {
|
||||
this._fd = -1;
|
||||
this._file = path.join(base, file);
|
||||
this._base = base;
|
||||
this._file = file;
|
||||
this._path = path.join(base, file);
|
||||
this._lruBranch = new LRUMap(LRU_BRANCH_COUNT);
|
||||
this._lruData = new LRUMap(LRU_DATA_COUNT);
|
||||
this._isCompressed = options && !isUndefined(options.isCompressed)
|
||||
@@ -47,7 +51,7 @@ export default class FileFlatDb implements BaseDb {
|
||||
}
|
||||
|
||||
open (): void {
|
||||
this._fd = this._open(this._file);
|
||||
this._fd = this._open(this._path);
|
||||
this._fileSize = fs.fstatSync(this._fd).size;
|
||||
|
||||
this._lruBranch.clear();
|
||||
@@ -66,10 +70,22 @@ export default class FileFlatDb implements BaseDb {
|
||||
empty (): void {
|
||||
this.close();
|
||||
|
||||
this._fd = this._open(this._file, true);
|
||||
this._fd = this._open(this._path, true);
|
||||
this._fileSize = fs.fstatSync(this._fd).size;
|
||||
}
|
||||
|
||||
rename (base: string, file: string): void {
|
||||
assert(this._fd === -1, 'Database cannot be open for renaming');
|
||||
|
||||
const oldPath = this._path;
|
||||
|
||||
this._base = base;
|
||||
this._file = file;
|
||||
this._path = path.join(base, file);
|
||||
|
||||
fs.renameSync(oldPath, this._path);
|
||||
}
|
||||
|
||||
maintain (fn: ProgressCb): void {
|
||||
assert(this._fd === -1, 'Database cannot be open for compacting');
|
||||
|
||||
|
||||
@@ -51,7 +51,11 @@ export default class FileTreeDb implements BaseDb {
|
||||
}
|
||||
|
||||
empty (): void {
|
||||
throw new Error('error is not implemented');
|
||||
l.error('empty() is not implemented');
|
||||
}
|
||||
|
||||
rename (base: string, file: string): void {
|
||||
l.error('rename() is not implemented');
|
||||
}
|
||||
|
||||
maintain (fn: ProgressCb): void {
|
||||
|
||||
@@ -45,6 +45,10 @@ export default class LruDb implements BaseDb {
|
||||
this.backing.empty();
|
||||
}
|
||||
|
||||
rename (base: string, file: string): void {
|
||||
this.backing.rename(base, file);
|
||||
}
|
||||
|
||||
maintain (fn: ProgressCb): void {
|
||||
this.backing.maintain(fn);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ export default class MemoryDb implements BaseDb {
|
||||
this.storage = {};
|
||||
}
|
||||
|
||||
rename (base: string, file: string): void {
|
||||
l.error('rename() is not implemented');
|
||||
}
|
||||
|
||||
maintain (fn: ProgressCb): void {
|
||||
fn({
|
||||
isCompleted: true,
|
||||
|
||||
@@ -62,6 +62,10 @@ export default class TransactionDb implements TxDb {
|
||||
this.backing.empty();
|
||||
}
|
||||
|
||||
rename (base: string, file: string): void {
|
||||
this.backing.rename(base, file);
|
||||
}
|
||||
|
||||
maintain (fn: ProgressCb): void {
|
||||
assert(this.txStarted === false, 'Cannot maintain inside an open transaction');
|
||||
|
||||
|
||||
Vendored
+1
@@ -18,6 +18,7 @@ export interface BaseDb {
|
||||
close (): void;
|
||||
open (): void;
|
||||
empty (): void;
|
||||
rename (base: string, file: string): void;
|
||||
|
||||
maintain (fn: ProgressCb): void;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user