mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
sqlite stream reader
This commit is contained in:
parent
615397f332
commit
1888de8728
@ -24,7 +24,8 @@ export const driverBase = {
|
||||
const analyser = new this.analyserClass(pool, this);
|
||||
analyser.singleObjectFilter = { ...name, typeField };
|
||||
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) {
|
||||
return this.analyseSingleObject(pool, name, 'tables');
|
||||
|
@ -40,7 +40,7 @@
|
||||
</script>
|
||||
|
||||
<ManagerInnerContainer width={managerSize}>
|
||||
{#each structure.columns as column, index}
|
||||
{#each structure.columns || [] as column, index}
|
||||
{#if index == editingColumn}
|
||||
<ColumnNameEditor
|
||||
defaultValue={column.columnName}
|
||||
@ -77,6 +77,6 @@
|
||||
dispatchChangeColumns($$props, cols => [...cols, { columnName }]);
|
||||
}}
|
||||
placeholder="New column"
|
||||
existingNames={structure.columns.map(x => x.columnName)}
|
||||
existingNames={(structure.columns || []).map(x => x.columnName)}
|
||||
/>
|
||||
</ManagerInnerContainer>
|
||||
|
@ -6,6 +6,15 @@ const { identify } = require('sql-query-identifier');
|
||||
|
||||
let Database;
|
||||
|
||||
async function waitForDrain(stream) {
|
||||
return new Promise((resolve) => {
|
||||
stream.once('drain', () => {
|
||||
// console.log('CONTINUE DRAIN');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function runStreamItem(client, sql, options, rowCounter) {
|
||||
const stmt = client.prepare(sql);
|
||||
if (stmt.reader) {
|
||||
@ -96,16 +105,36 @@ const driver = {
|
||||
options.done();
|
||||
// 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) {
|
||||
const pass = new stream.PassThrough({
|
||||
objectMode: true,
|
||||
highWaterMark: 100,
|
||||
});
|
||||
|
||||
// pass.write(structure)
|
||||
// pass.write(row1)
|
||||
// pass.write(row2)
|
||||
// pass.end()
|
||||
const stmt = pool.prepare(sql);
|
||||
const columns = stmt.columns();
|
||||
|
||||
pass.write({
|
||||
__isStreamHeader: true,
|
||||
...(structure || {
|
||||
columns: columns.map((col) => ({
|
||||
columnName: col.name,
|
||||
dataType: col.type,
|
||||
})),
|
||||
}),
|
||||
});
|
||||
this.readQueryTask(stmt, pass);
|
||||
|
||||
return pass;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user