correct saving jsonl data

This commit is contained in:
Jan Prochazka 2023-02-10 11:37:18 +01:00
parent cc9402dd84
commit dd46604069
4 changed files with 16 additions and 1 deletions

View File

@ -9,6 +9,7 @@ const getJslFileName = require('../utility/getJslFileName');
const { getLogger } = require('dbgate-tools');
const uuidv1 = require('uuid/v1');
const dbgateApi = require('../shell');
const jsldata = require('./jsldata');
const logger = getLogger('archive');
@ -109,6 +110,7 @@ module.exports = {
saveChangeSet_meta: true,
async saveChangeSet({ folder, file, changeSet }) {
await jsldata.closeDataStore(`archive://${folder}/${file}`);
const changedFilePath = path.join(resolveArchiveFolder(folder), `${file}.jsonl`);
const tmpchangedFilePath = path.join(resolveArchiveFolder(folder), `${file}-${uuidv1()}.jsonl`);
const reader = await dbgateApi.changeSetOverJsonLinesReader({ fileName: changedFilePath, changeSet });

View File

@ -113,6 +113,14 @@ module.exports = {
return datastore;
},
async closeDataStore(jslid) {
const datastore = this.datastores[jslid];
if (datastore) {
await datastore._closeReader();
delete this.datastores[jslid];
}
},
getInfo_meta: true,
async getInfo({ jslid }) {
const file = getJslFileName(jslid);

View File

@ -75,6 +75,7 @@ class JsonLinesDatastore {
}
_closeReader() {
// console.log('CLOSING READER', this.reader);
if (!this.reader) return;
const reader = this.reader;
this.reader = null;
@ -83,7 +84,7 @@ class JsonLinesDatastore {
// this.firstRowToBeReturned = null;
this.currentFilter = null;
this.currentSort = null;
reader.close(() => {});
return new Promise(resolve => reader.close(resolve));
}
async notifyChanged(callback) {
@ -97,6 +98,8 @@ class JsonLinesDatastore {
}
async _openReader(fileName) {
// console.log('OPENING READER', fileName);
// console.log(fs.readFileSync(fileName, 'utf-8'));
return new Promise((resolve, reject) =>
lineReader.open(fileName, (err, reader) => {
if (err) reject(err);

View File

@ -18,6 +18,7 @@
<script lang="ts">
import { changeSetContainsChanges, createChangeSet } from 'dbgate-datalib';
import { tick } from 'svelte';
import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte';
@ -73,6 +74,7 @@
changeSet: $changeSetStore.value,
});
dispatchChangeSet({ type: 'reset', value: createChangeSet() });
await tick();
runCommand('dataGrid.refresh');
}