sqlite sync query

This commit is contained in:
Jan Prochazka
2021-05-06 13:32:37 +02:00
parent a9c8cee08a
commit e251459512
3 changed files with 48 additions and 38 deletions

View File

@@ -0,0 +1,13 @@
diff --git a/node_modules/sql-query-identifier/lib/tokenizer.js b/node_modules/sql-query-identifier/lib/tokenizer.js
index f8980fe..bb03059 100644
--- a/node_modules/sql-query-identifier/lib/tokenizer.js
+++ b/node_modules/sql-query-identifier/lib/tokenizer.js
@@ -249,7 +249,7 @@ function skipWord(state, value) {
};
}
function isWhitespace(ch) {
- return ch === ' ' || ch === '\t' || ch === '\n';
+ return ch === ' ' || ch === '\t' || ch === '\n' || ch == '\r';
}
function isString(ch, dialect) {
const stringStart = dialect === 'mysql' ? ["'", '"'] : ["'"];

View File

@@ -121,7 +121,7 @@ const driver = {
return { rows: res.rows.map(row => zipDataRow(row, columns)), columns }; return { rows: res.rows.map(row => zipDataRow(row, columns)), columns };
}, },
async stream(client, sql, options) { async stream(client, sql, options) {
const sqlSplitted = identify(sql, { dialect: 'psql' }); const sqlSplitted = identify(sql, { dialect: 'psql', strict: false });
for (const sqlItem of sqlSplitted) { for (const sqlItem of sqlSplitted) {
await runStreamItem(client, sqlItem.text, options); await runStreamItem(client, sqlItem.text, options);

View File

@@ -6,9 +6,9 @@ const { identify } = require('sql-query-identifier');
let Database; let Database;
async function runStreamItem(client, sql, options) { function runStreamItem(client, sql, options) {
return new Promise((resolve, reject) => {
try { try {
console.log('RUN SQL ITEM', sql);
const stmt = client.prepare(sql); const stmt = client.prepare(sql);
if (stmt.reader) { if (stmt.reader) {
const columns = stmt.columns(); const columns = stmt.columns();
@@ -24,8 +24,6 @@ async function runStreamItem(client, sql, options) {
for (const row of stmt.iterate()) { for (const row of stmt.iterate()) {
options.row(row); options.row(row);
} }
resolve();
} else { } else {
const info = stmt.run(); const info = stmt.run();
options.info({ options.info({
@@ -33,7 +31,6 @@ async function runStreamItem(client, sql, options) {
time: new Date(), time: new Date(),
severity: 'info', severity: 'info',
}); });
resolve();
} }
} catch (error) { } catch (error) {
console.log('ERROR', error); console.log('ERROR', error);
@@ -45,9 +42,7 @@ async function runStreamItem(client, sql, options) {
time: new Date(), time: new Date(),
severity: 'error', severity: 'error',
}); });
resolve();
} }
});
} }
/** @type {import('dbgate-types').EngineDriver} */ /** @type {import('dbgate-types').EngineDriver} */
@@ -73,10 +68,12 @@ const driver = {
}; };
}, },
async stream(client, sql, options) { async stream(client, sql, options) {
const sqlSplitted = identify(sql, { dialect: 'sqlite' }); // console.log('CP1', sql);
const sqlSplitted = identify(sql, { dialect: 'sqlite', strict: false });
// console.log('CP2', sqlSplitted);
for (const sqlItem of sqlSplitted) { for (const sqlItem of sqlSplitted) {
await runStreamItem(client, sqlItem.text, options); runStreamItem(client, sqlItem.text, options);
} }
options.done(); options.done();