mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
correct saving jsonl data
This commit is contained in:
parent
cc9402dd84
commit
dd46604069
@ -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 });
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user