mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 08:43:57 +00:00
sqlite sync query
This commit is contained in:
13
patches/sql-query-identifier+2.1.0.patch
Normal file
13
patches/sql-query-identifier+2.1.0.patch
Normal 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' ? ["'", '"'] : ["'"];
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -6,48 +6,43 @@ 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();
|
||||||
// const rows = stmt.all();
|
// const rows = stmt.all();
|
||||||
|
|
||||||
options.recordset(
|
options.recordset(
|
||||||
columns.map((col) => ({
|
columns.map((col) => ({
|
||||||
columnName: col.name,
|
columnName: col.name,
|
||||||
dataType: col.type,
|
dataType: col.type,
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const row of stmt.iterate()) {
|
for (const row of stmt.iterate()) {
|
||||||
options.row(row);
|
options.row(row);
|
||||||
}
|
|
||||||
|
|
||||||
resolve();
|
|
||||||
} else {
|
|
||||||
const info = stmt.run();
|
|
||||||
options.info({
|
|
||||||
message: `${info.changes} rows affected`,
|
|
||||||
time: new Date(),
|
|
||||||
severity: 'info',
|
|
||||||
});
|
|
||||||
resolve();
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} else {
|
||||||
console.log('ERROR', error);
|
const info = stmt.run();
|
||||||
const { message, lineNumber, procName } = error;
|
|
||||||
options.info({
|
options.info({
|
||||||
message,
|
message: `${info.changes} rows affected`,
|
||||||
line: lineNumber,
|
|
||||||
procedure: procName,
|
|
||||||
time: new Date(),
|
time: new Date(),
|
||||||
severity: 'error',
|
severity: 'info',
|
||||||
});
|
});
|
||||||
resolve();
|
|
||||||
}
|
}
|
||||||
});
|
} catch (error) {
|
||||||
|
console.log('ERROR', error);
|
||||||
|
const { message, lineNumber, procName } = error;
|
||||||
|
options.info({
|
||||||
|
message,
|
||||||
|
line: lineNumber,
|
||||||
|
procedure: procName,
|
||||||
|
time: new Date(),
|
||||||
|
severity: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @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();
|
||||||
|
|||||||
Reference in New Issue
Block a user