mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 04:56:00 +00:00
sqlite stream reader
This commit is contained in:
@@ -24,7 +24,8 @@ export const driverBase = {
|
|||||||
const analyser = new this.analyserClass(pool, this);
|
const analyser = new this.analyserClass(pool, this);
|
||||||
analyser.singleObjectFilter = { ...name, typeField };
|
analyser.singleObjectFilter = { ...name, typeField };
|
||||||
const res = await analyser.fullAnalysis();
|
const res = await analyser.fullAnalysis();
|
||||||
return res.tables[0];
|
if (res[typeField].length == 1) return res[typeField][0];
|
||||||
|
return res[typeField].find(x => x.pureName == name.pureName && x.schemaName == name.schemaName);
|
||||||
},
|
},
|
||||||
analyseSingleTable(pool, name) {
|
analyseSingleTable(pool, name) {
|
||||||
return this.analyseSingleObject(pool, name, 'tables');
|
return this.analyseSingleObject(pool, name, 'tables');
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ManagerInnerContainer width={managerSize}>
|
<ManagerInnerContainer width={managerSize}>
|
||||||
{#each structure.columns as column, index}
|
{#each structure.columns || [] as column, index}
|
||||||
{#if index == editingColumn}
|
{#if index == editingColumn}
|
||||||
<ColumnNameEditor
|
<ColumnNameEditor
|
||||||
defaultValue={column.columnName}
|
defaultValue={column.columnName}
|
||||||
@@ -77,6 +77,6 @@
|
|||||||
dispatchChangeColumns($$props, cols => [...cols, { columnName }]);
|
dispatchChangeColumns($$props, cols => [...cols, { columnName }]);
|
||||||
}}
|
}}
|
||||||
placeholder="New column"
|
placeholder="New column"
|
||||||
existingNames={structure.columns.map(x => x.columnName)}
|
existingNames={(structure.columns || []).map(x => x.columnName)}
|
||||||
/>
|
/>
|
||||||
</ManagerInnerContainer>
|
</ManagerInnerContainer>
|
||||||
|
|||||||
@@ -6,6 +6,15 @@ const { identify } = require('sql-query-identifier');
|
|||||||
|
|
||||||
let Database;
|
let Database;
|
||||||
|
|
||||||
|
async function waitForDrain(stream) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
stream.once('drain', () => {
|
||||||
|
// console.log('CONTINUE DRAIN');
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function runStreamItem(client, sql, options, rowCounter) {
|
function runStreamItem(client, sql, options, rowCounter) {
|
||||||
const stmt = client.prepare(sql);
|
const stmt = client.prepare(sql);
|
||||||
if (stmt.reader) {
|
if (stmt.reader) {
|
||||||
@@ -96,16 +105,36 @@ const driver = {
|
|||||||
options.done();
|
options.done();
|
||||||
// return stream;
|
// return stream;
|
||||||
},
|
},
|
||||||
|
async readQueryTask(stmt, pass) {
|
||||||
|
// let sent = 0;
|
||||||
|
for (const row of stmt.iterate()) {
|
||||||
|
// sent++;
|
||||||
|
if (!pass.write(row)) {
|
||||||
|
// console.log('WAIT DRAIN', sent);
|
||||||
|
await waitForDrain(pass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pass.end();
|
||||||
|
},
|
||||||
async readQuery(pool, sql, structure) {
|
async readQuery(pool, sql, structure) {
|
||||||
const pass = new stream.PassThrough({
|
const pass = new stream.PassThrough({
|
||||||
objectMode: true,
|
objectMode: true,
|
||||||
highWaterMark: 100,
|
highWaterMark: 100,
|
||||||
});
|
});
|
||||||
|
|
||||||
// pass.write(structure)
|
const stmt = pool.prepare(sql);
|
||||||
// pass.write(row1)
|
const columns = stmt.columns();
|
||||||
// pass.write(row2)
|
|
||||||
// pass.end()
|
pass.write({
|
||||||
|
__isStreamHeader: true,
|
||||||
|
...(structure || {
|
||||||
|
columns: columns.map((col) => ({
|
||||||
|
columnName: col.name,
|
||||||
|
dataType: col.type,
|
||||||
|
})),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
this.readQueryTask(stmt, pass);
|
||||||
|
|
||||||
return pass;
|
return pass;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user