mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 00:56:02 +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 { jsldir } = require('../utility/directories');
|
||||||
const socket = require('../utility/socket');
|
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 = {
|
module.exports = {
|
||||||
openedReaders: {},
|
openedReaders: {},
|
||||||
|
|
||||||
@@ -37,7 +53,10 @@ module.exports = {
|
|||||||
|
|
||||||
openReader(jslid) {
|
openReader(jslid) {
|
||||||
// console.log('OPENING READER');
|
// 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`);
|
const file = path.join(jsldir(), `${jslid}.jsonl`);
|
||||||
return new Promise((resolve, reject) =>
|
return new Promise((resolve, reject) =>
|
||||||
lineReader.open(file, (err, reader) => {
|
lineReader.open(file, (err, reader) => {
|
||||||
@@ -58,15 +77,18 @@ module.exports = {
|
|||||||
if (!this.openedReaders[jslid]) {
|
if (!this.openedReaders[jslid]) {
|
||||||
await this.openReader(jslid);
|
await this.openReader(jslid);
|
||||||
}
|
}
|
||||||
|
await this.readLine(jslid); // skip structure
|
||||||
while (this.openedReaders[jslid].readedCount < offset) {
|
while (this.openedReaders[jslid].readedCount < offset) {
|
||||||
await this.readLine(jslid);
|
await this.readLine(jslid);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getInfo_meta: 'get',
|
getInfo_meta: 'get',
|
||||||
getInfo({ jslid }) {
|
async getInfo({ jslid }) {
|
||||||
const file = path.join(jsldir(), `${jslid}.jsonl.info`);
|
const file = path.join(jsldir(), `${jslid}.jsonl`);
|
||||||
return JSON.parse(fs.readFileSync(file, 'utf-8'));
|
const firstLine = await readFirstLine(file);
|
||||||
|
if (firstLine) return JSON.parse(firstLine);
|
||||||
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
getRows_meta: 'get',
|
getRows_meta: 'get',
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ class TableWriter {
|
|||||||
constructor(columns) {
|
constructor(columns) {
|
||||||
this.jslid = uuidv1();
|
this.jslid = uuidv1();
|
||||||
this.currentFile = path.join(jsldir(), `${this.jslid}.jsonl`);
|
this.currentFile = path.join(jsldir(), `${this.jslid}.jsonl`);
|
||||||
this.currentStream = fs.createWriteStream(this.currentFile);
|
|
||||||
this.currentRowCount = 0;
|
this.currentRowCount = 0;
|
||||||
this.currentChangeIndex = 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);
|
this.writeCurrentStats(false, false);
|
||||||
process.send({ msgtype: 'recordset', jslid: this.jslid });
|
process.send({ msgtype: 'recordset', jslid: this.jslid });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user