mirror of
https://github.com/dbgate/dbgate
synced 2024-11-08 04:35:58 +00:00
jsl data source - renamed private methods
This commit is contained in:
parent
541f064ddb
commit
7681f9e1ec
@ -11,7 +11,7 @@ class JsonLinesDatastore {
|
|||||||
this.notifyChangedCallback = null;
|
this.notifyChangedCallback = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
closeReader() {
|
_closeReader() {
|
||||||
if (!this.reader) return;
|
if (!this.reader) return;
|
||||||
const reader = this.reader;
|
const reader = this.reader;
|
||||||
this.reader = null;
|
this.reader = null;
|
||||||
@ -23,14 +23,14 @@ class JsonLinesDatastore {
|
|||||||
async notifyChanged(callback) {
|
async notifyChanged(callback) {
|
||||||
this.notifyChangedCallback = callback;
|
this.notifyChangedCallback = callback;
|
||||||
await lock.acquire('reader', async () => {
|
await lock.acquire('reader', async () => {
|
||||||
this.closeReader();
|
this._closeReader();
|
||||||
});
|
});
|
||||||
const call = this.notifyChangedCallback;
|
const call = this.notifyChangedCallback;
|
||||||
this.notifyChangedCallback = null;
|
this.notifyChangedCallback = null;
|
||||||
if (call) call();
|
if (call) call();
|
||||||
}
|
}
|
||||||
|
|
||||||
async openReader() {
|
async _openReader() {
|
||||||
return new Promise((resolve, reject) =>
|
return new Promise((resolve, reject) =>
|
||||||
lineReader.open(this.file, (err, reader) => {
|
lineReader.open(this.file, (err, reader) => {
|
||||||
if (err) reject(err);
|
if (err) reject(err);
|
||||||
@ -39,7 +39,7 @@ class JsonLinesDatastore {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
readLine() {
|
_readLine() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const reader = this.reader;
|
const reader = this.reader;
|
||||||
if (!reader.hasNextLine()) {
|
if (!reader.hasNextLine()) {
|
||||||
@ -55,28 +55,28 @@ class JsonLinesDatastore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async ensureReader(offset) {
|
async _ensureReader(offset) {
|
||||||
if (this.readedDataRowCount > offset) {
|
if (this.readedDataRowCount > offset) {
|
||||||
this.closeReader();
|
this._closeReader();
|
||||||
}
|
}
|
||||||
if (!this.reader) {
|
if (!this.reader) {
|
||||||
const reader = await this.openReader();
|
const reader = await this._openReader();
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
}
|
}
|
||||||
if (!this.readedSchemaRow) {
|
if (!this.readedSchemaRow) {
|
||||||
await this.readLine(); // skip structure
|
await this._readLine(); // skip structure
|
||||||
}
|
}
|
||||||
while (this.readedDataRowCount < offset) {
|
while (this.readedDataRowCount < offset) {
|
||||||
await this.readLine();
|
await this._readLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRows(offset, limit) {
|
async getRows(offset, limit) {
|
||||||
const res = [];
|
const res = [];
|
||||||
await lock.acquire('reader', async () => {
|
await lock.acquire('reader', async () => {
|
||||||
await this.ensureReader(offset);
|
await this._ensureReader(offset);
|
||||||
for (let i = 0; i < limit; i += 1) {
|
for (let i = 0; i < limit; i += 1) {
|
||||||
const line = await this.readLine();
|
const line = await this._readLine();
|
||||||
if (line == null) break;
|
if (line == null) break;
|
||||||
res.push(JSON.parse(line));
|
res.push(JSON.parse(line));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user