diff --git a/packages/web/src/modals/ConnectionModal.svelte b/packages/web/src/modals/ConnectionModal.svelte index 8a863ab4..002c0c19 100644 --- a/packages/web/src/modals/ConnectionModal.svelte +++ b/packages/web/src/modals/ConnectionModal.svelte @@ -51,7 +51,7 @@ async function handleSubmit(e) { axiosInstance.post('connections/save', { ...e.detail, - singleDatabase: e.detail.defaultDatabase ? e.detail.singleDatabase : false, + singleDatabase: driver?.isFileDatabase || (e.detail.defaultDatabase ? e.detail.singleDatabase : false), }); closeCurrentModal(); } diff --git a/packages/web/src/widgets/SqlObjectListWrapper.svelte b/packages/web/src/widgets/SqlObjectListWrapper.svelte index 1c62b4d7..a7f7852e 100644 --- a/packages/web/src/widgets/SqlObjectListWrapper.svelte +++ b/packages/web/src/widgets/SqlObjectListWrapper.svelte @@ -6,10 +6,11 @@ import WidgetsInnerContainer from './WidgetsInnerContainer.svelte'; $: conid = _.get($currentDatabase, 'connection._id'); + $: singleDatabase = _.get($currentDatabase, 'connection.singleDatabase'); $: database = _.get($currentDatabase, 'name'); -{#if conid && database} +{#if conid && (database || singleDatabase)} {:else} diff --git a/plugins/dbgate-plugin-mongo/src/backend/Analyser.js b/plugins/dbgate-plugin-mongo/src/backend/Analyser.js index 667a895d..d710544a 100644 --- a/plugins/dbgate-plugin-mongo/src/backend/Analyser.js +++ b/plugins/dbgate-plugin-mongo/src/backend/Analyser.js @@ -8,14 +8,11 @@ class Analyser extends DatabaseAnalyser { async _runAnalysis() { const collections = await this.pool.__getDatabase().listCollections().toArray(); - const res = this.mergeAnalyseResult( - { - collections: collections.map((x) => ({ - pureName: x.name, - })), - }, - (x) => x.pureName - ); + const res = this.mergeAnalyseResult({ + collections: collections.map((x) => ({ + pureName: x.name, + })), + }); // console.log('MERGED', res); return res; } diff --git a/plugins/dbgate-plugin-sqlite/src/backend/Analyser.js b/plugins/dbgate-plugin-sqlite/src/backend/Analyser.js index 3e176ddc..abf30182 100644 --- a/plugins/dbgate-plugin-sqlite/src/backend/Analyser.js +++ b/plugins/dbgate-plugin-sqlite/src/backend/Analyser.js @@ -4,6 +4,23 @@ class Analyser extends DatabaseAnalyser { constructor(pool, driver) { super(pool, driver); } + + async _runAnalysis() { + const tables = await this.driver.query(this.pool, "select * from sqlite_master where type='table'"); + console.log('tables', tables); + + const res = this.mergeAnalyseResult( + { + tables: tables.rows.map((x) => ({ + pureName: x.name, + objectId: x.name, + })), + }, + (x) => x.pureName + ); + // console.log('MERGED', res); + return res; + } } module.exports = Analyser; diff --git a/plugins/dbgate-plugin-sqlite/src/backend/driver.js b/plugins/dbgate-plugin-sqlite/src/backend/driver.js index ea7a583f..a70669dd 100644 --- a/plugins/dbgate-plugin-sqlite/src/backend/driver.js +++ b/plugins/dbgate-plugin-sqlite/src/backend/driver.js @@ -3,28 +3,28 @@ const stream = require('stream'); const driverBase = require('../frontend/driver'); const Analyser = require('./Analyser'); -let sqlite3; +let Database; /** @type {import('dbgate-types').EngineDriver} */ const driver = { ...driverBase, analyserClass: Analyser, - async connect({ server, port, user, password, database }) { - const pool = new NativePool({ - server, - port, - user, - password, - database, - }); - await pool.connect(); + async connect({ databaseFile }) { + const pool = new Database(databaseFile); return pool; }, // @ts-ignore async query(pool, sql) { + const stmt = pool.prepare(sql); + // stmt.raw(); + const columns = stmt.columns(); + const rows = stmt.all(); return { - rows: [], - columns: [], + rows, + columns: columns.map((col) => ({ + columnName: col.name, + dataType: col.type, + })), }; }, async stream(pool, sql, options) { @@ -47,16 +47,13 @@ const driver = { return createBulkInsertStreamBase(this, stream, pool, name, options); }, async getVersion(pool) { - return { version: '1.0.0' }; - }, - async listDatabases(pool) { - return [{ name: 'db1' }, { name: 'db2' }]; + return { version: 'SQLite 3' }; }, }; driver.initialize = (dbgateEnv) => { if (dbgateEnv.nativeModules && dbgateEnv.nativeModules['better-sqlite3']) { - sqlite3 = dbgateEnv.nativeModules['better-sqlite3'](); + Database = dbgateEnv.nativeModules['better-sqlite3'](); } }; diff --git a/plugins/dbgate-plugin-sqlite/src/backend/index.js b/plugins/dbgate-plugin-sqlite/src/backend/index.js index 4812dbd5..7e72de05 100644 --- a/plugins/dbgate-plugin-sqlite/src/backend/index.js +++ b/plugins/dbgate-plugin-sqlite/src/backend/index.js @@ -3,4 +3,7 @@ const driver = require('./driver'); module.exports = { packageName: 'dbgate-plugin-sqlite', driver, + initialize(dbgateEnv) { + driver.initialize(dbgateEnv); + }, };