diff --git a/packages/tools/src/driverBase.ts b/packages/tools/src/driverBase.ts index 1132af43..c5ce2201 100644 --- a/packages/tools/src/driverBase.ts +++ b/packages/tools/src/driverBase.ts @@ -25,7 +25,9 @@ export const driverBase = { analyser.singleObjectFilter = { ...name, typeField }; const res = await analyser.fullAnalysis(); if (res[typeField].length == 1) return res[typeField][0]; - return res[typeField].find(x => x.pureName == name.pureName && x.schemaName == name.schemaName); + const obj = res[typeField].find(x => x.pureName == name.pureName && x.schemaName == name.schemaName); + // console.log('FIND', name, obj); + return obj; }, analyseSingleTable(pool, name) { return this.analyseSingleObject(pool, name, 'tables'); diff --git a/plugins/dbgate-plugin-sqlite/src/backend/Analyser.js b/plugins/dbgate-plugin-sqlite/src/backend/Analyser.js index c2356246..927192b4 100644 --- a/plugins/dbgate-plugin-sqlite/src/backend/Analyser.js +++ b/plugins/dbgate-plugin-sqlite/src/backend/Analyser.js @@ -24,8 +24,10 @@ class Analyser extends DatabaseAnalyser { 'tables', tables.rows.map((x) => x.name) )) { - const info = await this.driver.query(this.pool, `pragma table_info('${tableName}')`); const tableObj = tableList.find((x) => x.pureName == tableName); + if (!tableObj) continue; + + const info = await this.driver.query(this.pool, `pragma table_info('${tableName}')`); tableObj.columns = info.rows.map((col) => ({ columnName: col.name, dataType: col.type, diff --git a/plugins/dbgate-plugin-sqlite/src/backend/driver.js b/plugins/dbgate-plugin-sqlite/src/backend/driver.js index 5fbfebf0..bdce4763 100644 --- a/plugins/dbgate-plugin-sqlite/src/backend/driver.js +++ b/plugins/dbgate-plugin-sqlite/src/backend/driver.js @@ -3,6 +3,7 @@ const stream = require('stream'); const driverBase = require('../frontend/driver'); const Analyser = require('./Analyser'); const { identify } = require('sql-query-identifier'); +const { createBulkInsertStreamBase, makeUniqueColumnNames } = require('dbgate-tools'); let Database; @@ -59,15 +60,23 @@ const driver = { async query(pool, sql) { const stmt = pool.prepare(sql); // stmt.raw(); - const columns = stmt.columns(); - const rows = stmt.all(); - return { - rows, - columns: columns.map((col) => ({ - columnName: col.name, - dataType: col.type, - })), - }; + if (stmt.reader) { + const columns = stmt.columns(); + const rows = stmt.all(); + return { + rows, + columns: columns.map((col) => ({ + columnName: col.name, + dataType: col.type, + })), + }; + } else { + stmt.run(); + return { + rows: [], + columns: [], + }; + } }, async stream(client, sql, options) { const sqlSplitted = identify(sql, { dialect: 'sqlite', strict: false });