SYNC: Merge pull request #7 from dbgate/feature/applog

This commit is contained in:
Jan Prochazka
2025-08-05 17:13:33 +02:00
committed by Diflow
parent ac0aebd751
commit a96f1d0b49
83 changed files with 1014 additions and 242 deletions

View File

@@ -7,15 +7,15 @@ const AsyncLock = require('async-lock');
const lock = new AsyncLock();
const stableStringify = require('json-stable-stringify');
const { evaluateCondition } = require('dbgate-sqltree');
const requirePluginFunction = require('./requirePluginFunction');
const esort = require('external-sorting');
const { jsldir } = require('./directories');
const LineReader = require('./LineReader');
class JsonLinesDatastore {
constructor(file, formatterFunction) {
constructor(file, formatterFunction, resolveNextFile = null) {
this.file = file;
this.formatterFunction = formatterFunction;
this.resolveNextFile = resolveNextFile;
this.reader = null;
this.readedDataRowCount = 0;
this.readedSchemaRow = false;
@@ -23,7 +23,12 @@ class JsonLinesDatastore {
this.notifyChangedCallback = null;
this.currentFilter = null;
this.currentSort = null;
this.rowFormatter = requirePluginFunction(formatterFunction);
this.currentFileName = null;
if (formatterFunction) {
const requirePluginFunction = require('./requirePluginFunction');
this.rowFormatter = requirePluginFunction(formatterFunction);
}
this.sortedFiles = {};
}
@@ -67,6 +72,7 @@ class JsonLinesDatastore {
// this.firstRowToBeReturned = null;
this.currentFilter = null;
this.currentSort = null;
this.currentFileName = null;
await reader.close();
}
@@ -100,8 +106,18 @@ class JsonLinesDatastore {
// return res;
// }
for (;;) {
const line = await this.reader.readLine();
if (!line) {
let line = await this.reader.readLine();
while (!line) {
if (!this.currentSort && this.resolveNextFile) {
const nextFile = await this.resolveNextFile(this.currentFileName);
if (nextFile) {
await this.reader.close();
this.reader = await this._openReader(nextFile);
this.currentFileName = nextFile;
line = await this.reader.readLine();
continue;
}
}
// EOF
return null;
}
@@ -173,6 +189,7 @@ class JsonLinesDatastore {
}
if (!this.reader) {
const reader = await this._openReader(sort ? this.sortedFiles[stableStringify(sort)] : this.file);
this.currentFileName = this.file;
this.reader = reader;
this.currentFilter = filter;
this.currentSort = sort;