mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 22:36:01 +00:00
jsl data - first line is structure
This commit is contained in:
@@ -4,6 +4,22 @@ const lineReader = require('line-reader');
|
||||
const { jsldir } = require('../utility/directories');
|
||||
const socket = require('../utility/socket');
|
||||
|
||||
function readFirstLine(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
lineReader.open(file, (err, reader) => {
|
||||
if (err) reject(err);
|
||||
if (reader.hasNextLine()) {
|
||||
reader.nextLine((err, line) => {
|
||||
if (err) reject(err);
|
||||
resolve(line);
|
||||
});
|
||||
} else {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
openedReaders: {},
|
||||
|
||||
@@ -37,7 +53,10 @@ module.exports = {
|
||||
|
||||
openReader(jslid) {
|
||||
// console.log('OPENING READER');
|
||||
console.log('OPENING READER, LINES=', fs.readFileSync(path.join(jsldir(), `${jslid}.jsonl`), 'utf-8').split('\n').length);
|
||||
console.log(
|
||||
'OPENING READER, LINES=',
|
||||
fs.readFileSync(path.join(jsldir(), `${jslid}.jsonl`), 'utf-8').split('\n').length
|
||||
);
|
||||
const file = path.join(jsldir(), `${jslid}.jsonl`);
|
||||
return new Promise((resolve, reject) =>
|
||||
lineReader.open(file, (err, reader) => {
|
||||
@@ -58,15 +77,18 @@ module.exports = {
|
||||
if (!this.openedReaders[jslid]) {
|
||||
await this.openReader(jslid);
|
||||
}
|
||||
await this.readLine(jslid); // skip structure
|
||||
while (this.openedReaders[jslid].readedCount < offset) {
|
||||
await this.readLine(jslid);
|
||||
}
|
||||
},
|
||||
|
||||
getInfo_meta: 'get',
|
||||
getInfo({ jslid }) {
|
||||
const file = path.join(jsldir(), `${jslid}.jsonl.info`);
|
||||
return JSON.parse(fs.readFileSync(file, 'utf-8'));
|
||||
async getInfo({ jslid }) {
|
||||
const file = path.join(jsldir(), `${jslid}.jsonl`);
|
||||
const firstLine = await readFirstLine(file);
|
||||
if (firstLine) return JSON.parse(firstLine);
|
||||
return null;
|
||||
},
|
||||
|
||||
getRows_meta: 'get',
|
||||
|
||||
@@ -17,10 +17,10 @@ class TableWriter {
|
||||
constructor(columns) {
|
||||
this.jslid = uuidv1();
|
||||
this.currentFile = path.join(jsldir(), `${this.jslid}.jsonl`);
|
||||
this.currentStream = fs.createWriteStream(this.currentFile);
|
||||
this.currentRowCount = 0;
|
||||
this.currentChangeIndex = 0;
|
||||
fs.writeFileSync(`${this.currentFile}.info`, JSON.stringify(columns));
|
||||
fs.writeFileSync(this.currentFile, JSON.stringify(columns) + '\n');
|
||||
this.currentStream = fs.createWriteStream(this.currentFile, { flags: 'a' });
|
||||
this.writeCurrentStats(false, false);
|
||||
process.send({ msgtype: 'recordset', jslid: this.jslid });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user