fix: remove temp duckdb connection cache

This commit is contained in:
Nybkox
2025-04-08 18:06:46 +02:00
parent 18faf89b89
commit e7c42f3623

View File

@@ -21,29 +21,16 @@ function getDuckDb() {
return duckDb; return duckDb;
} }
let fileToCon = {};
async function getConnection(file) {
if (fileToCon[file]) {
fileToCon[file].close();
}
const duckDb = getDuckDb();
const instance = await duckDb.DuckDBInstance.create(file);
console.log('DuckDB instance created', instance);
const connection = await instance.connect();
fileToCon[file] = connection;
return fileToCon[file];
}
/** @type {import('dbgate-types').EngineDriver<import('@duckdb/node-api').DuckDBConnection>} */ /** @type {import('dbgate-types').EngineDriver<import('@duckdb/node-api').DuckDBConnection>} */
const driver = { const driver = {
...driverBase, ...driverBase,
analyserClass: Analyser, analyserClass: Analyser,
async connect({ databaseFile, isReadOnly }) { async connect({ databaseFile, isReadOnly }) {
const instance = await getDuckDb().DuckDBInstance.create(databaseFile);
const connection = await instance.connect();
return { return {
client: await getConnection(databaseFile), client: connection,
}; };
}, },
async close(dbhan) { async close(dbhan) {