mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 00:16:00 +00:00
close dbhandles after shell script (missing tableReader)
This commit is contained in:
@@ -19,16 +19,18 @@ async function dataDuplicator({
|
|||||||
systemConnection,
|
systemConnection,
|
||||||
}) {
|
}) {
|
||||||
if (!driver) driver = requireEngineDriver(connection);
|
if (!driver) driver = requireEngineDriver(connection);
|
||||||
const pool = systemConnection || (await connectUtility(driver, connection, 'write'));
|
|
||||||
|
|
||||||
|
const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
|
||||||
|
|
||||||
|
try {
|
||||||
logger.info(`Connected.`);
|
logger.info(`Connected.`);
|
||||||
|
|
||||||
if (!analysedStructure) {
|
if (!analysedStructure) {
|
||||||
analysedStructure = await driver.analyseFull(pool);
|
analysedStructure = await driver.analyseFull(dbhan);
|
||||||
}
|
}
|
||||||
|
|
||||||
const dupl = new DataDuplicator(
|
const dupl = new DataDuplicator(
|
||||||
pool,
|
dbhan,
|
||||||
driver,
|
driver,
|
||||||
analysedStructure,
|
analysedStructure,
|
||||||
items.map(item => ({
|
items.map(item => ({
|
||||||
@@ -45,6 +47,11 @@ async function dataDuplicator({
|
|||||||
);
|
);
|
||||||
|
|
||||||
await dupl.run();
|
await dupl.run();
|
||||||
|
} finally {
|
||||||
|
if (!systemConnection) {
|
||||||
|
await driver.close(dbhan);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = dataDuplicator;
|
module.exports = dataDuplicator;
|
||||||
|
|||||||
@@ -27,15 +27,23 @@ async function dumpDatabase({
|
|||||||
logger.info(`Dumping database`);
|
logger.info(`Dumping database`);
|
||||||
|
|
||||||
if (!driver) driver = requireEngineDriver(connection);
|
if (!driver) driver = requireEngineDriver(connection);
|
||||||
const pool = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
|
|
||||||
|
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
|
||||||
|
|
||||||
|
try {
|
||||||
logger.info(`Connected.`);
|
logger.info(`Connected.`);
|
||||||
|
|
||||||
const dumper = await driver.createBackupDumper(pool, {
|
const dumper = await driver.createBackupDumper(dbhan, {
|
||||||
outputFile,
|
outputFile,
|
||||||
databaseName,
|
databaseName,
|
||||||
schemaName,
|
schemaName,
|
||||||
});
|
});
|
||||||
await doDump(dumper);
|
await doDump(dumper);
|
||||||
|
} finally {
|
||||||
|
if (!systemConnection) {
|
||||||
|
await driver.close(dbhan);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = dumpDatabase;
|
module.exports = dumpDatabase;
|
||||||
|
|||||||
@@ -9,13 +9,16 @@ async function executeQuery({ connection = undefined, systemConnection = undefin
|
|||||||
|
|
||||||
if (!driver) driver = requireEngineDriver(connection);
|
if (!driver) driver = requireEngineDriver(connection);
|
||||||
const dbhan = systemConnection || (await connectUtility(driver, connection, 'script'));
|
const dbhan = systemConnection || (await connectUtility(driver, connection, 'script'));
|
||||||
|
|
||||||
|
try {
|
||||||
logger.info(`Connected.`);
|
logger.info(`Connected.`);
|
||||||
|
|
||||||
await driver.script(dbhan, sql);
|
await driver.script(dbhan, sql);
|
||||||
|
} finally {
|
||||||
if (!systemConnection) {
|
if (!systemConnection) {
|
||||||
await driver.close(dbhan);
|
await driver.close(dbhan);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = executeQuery;
|
module.exports = executeQuery;
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ async function generateDeploySql({
|
|||||||
if (!driver) driver = requireEngineDriver(connection);
|
if (!driver) driver = requireEngineDriver(connection);
|
||||||
|
|
||||||
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
|
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
|
||||||
|
|
||||||
|
try {
|
||||||
if (!analysedStructure) {
|
if (!analysedStructure) {
|
||||||
analysedStructure = await driver.analyseFull(dbhan);
|
analysedStructure = await driver.analyseFull(dbhan);
|
||||||
}
|
}
|
||||||
@@ -56,10 +58,12 @@ async function generateDeploySql({
|
|||||||
driver
|
driver
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
} finally {
|
||||||
if (!systemConnection) {
|
if (!systemConnection) {
|
||||||
await driver.close(dbhan);
|
await driver.close(dbhan);
|
||||||
}
|
}
|
||||||
return res;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = generateDeploySql;
|
module.exports = generateDeploySql;
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ async function importDatabase({ connection = undefined, systemConnection = undef
|
|||||||
|
|
||||||
if (!driver) driver = requireEngineDriver(connection);
|
if (!driver) driver = requireEngineDriver(connection);
|
||||||
const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
|
const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
|
||||||
|
try {
|
||||||
logger.info(`Connected.`);
|
logger.info(`Connected.`);
|
||||||
|
|
||||||
logger.info(`Input file: ${inputFile}`);
|
logger.info(`Input file: ${inputFile}`);
|
||||||
@@ -74,6 +75,11 @@ async function importDatabase({ connection = undefined, systemConnection = undef
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
splittedStream.pipe(importStream);
|
splittedStream.pipe(importStream);
|
||||||
await awaitStreamEnd(importStream);
|
await awaitStreamEnd(importStream);
|
||||||
|
} finally {
|
||||||
|
if (!systemConnection) {
|
||||||
|
await driver.close(dbhan);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = importDatabase;
|
module.exports = importDatabase;
|
||||||
|
|||||||
@@ -9,13 +9,19 @@ async function loadDatabase({ connection = undefined, systemConnection = undefin
|
|||||||
logger.info(`Analysing database`);
|
logger.info(`Analysing database`);
|
||||||
|
|
||||||
if (!driver) driver = requireEngineDriver(connection);
|
if (!driver) driver = requireEngineDriver(connection);
|
||||||
const pool = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
|
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
|
||||||
|
try {
|
||||||
logger.info(`Connected.`);
|
logger.info(`Connected.`);
|
||||||
|
|
||||||
const dbInfo = await driver.analyseFull(pool);
|
const dbInfo = await driver.analyseFull(dbhan);
|
||||||
logger.info(`Analyse finished`);
|
logger.info(`Analyse finished`);
|
||||||
|
|
||||||
await exportDbModel(dbInfo, outputDir);
|
await exportDbModel(dbInfo, outputDir);
|
||||||
|
} finally {
|
||||||
|
if (!systemConnection) {
|
||||||
|
await driver.close(dbhan);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = loadDatabase;
|
module.exports = loadDatabase;
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ const requireEngineDriver = require('../utility/requireEngineDriver');
|
|||||||
const connectUtility = require('../utility/connectUtility');
|
const connectUtility = require('../utility/connectUtility');
|
||||||
const logger = getLogger('tableReader');
|
const logger = getLogger('tableReader');
|
||||||
|
|
||||||
async function tableReader({ connection, pureName, schemaName }) {
|
async function tableReader({ connection, systemConnection, pureName, schemaName }) {
|
||||||
const driver = requireEngineDriver(connection);
|
const driver = requireEngineDriver(connection);
|
||||||
const pool = await connectUtility(driver, connection, 'read');
|
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
|
||||||
logger.info(`Connected.`);
|
logger.info(`Connected.`);
|
||||||
|
|
||||||
const fullName = { pureName, schemaName };
|
const fullName = { pureName, schemaName };
|
||||||
@@ -14,26 +14,26 @@ async function tableReader({ connection, pureName, schemaName }) {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
logger.info(`Reading collection ${fullNameToString(fullName)}`);
|
logger.info(`Reading collection ${fullNameToString(fullName)}`);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return await driver.readQuery(pool, JSON.stringify(fullName));
|
return await driver.readQuery(dbhan, JSON.stringify(fullName));
|
||||||
}
|
}
|
||||||
|
|
||||||
const table = await driver.analyseSingleObject(pool, fullName, 'tables');
|
const table = await driver.analyseSingleObject(dbhan, fullName, 'tables');
|
||||||
const query = `select * from ${quoteFullName(driver.dialect, fullName)}`;
|
const query = `select * from ${quoteFullName(driver.dialect, fullName)}`;
|
||||||
if (table) {
|
if (table) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
logger.info(`Reading table ${fullNameToString(table)}`);
|
logger.info(`Reading table ${fullNameToString(table)}`);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return await driver.readQuery(pool, query, table);
|
return await driver.readQuery(dbhan, query, table);
|
||||||
}
|
}
|
||||||
const view = await driver.analyseSingleObject(pool, fullName, 'views');
|
const view = await driver.analyseSingleObject(dbhan, fullName, 'views');
|
||||||
if (view) {
|
if (view) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
logger.info(`Reading view ${fullNameToString(view)}`);
|
logger.info(`Reading view ${fullNameToString(view)}`);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return await driver.readQuery(pool, query, view);
|
return await driver.readQuery(dbhan, query, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await driver.readQuery(pool, query);
|
return await driver.readQuery(dbhan, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = tableReader;
|
module.exports = tableReader;
|
||||||
|
|||||||
@@ -9,10 +9,16 @@ async function tableWriter({ connection, schemaName, pureName, driver, systemCon
|
|||||||
if (!driver) {
|
if (!driver) {
|
||||||
driver = requireEngineDriver(connection);
|
driver = requireEngineDriver(connection);
|
||||||
}
|
}
|
||||||
const pool = systemConnection || (await connectUtility(driver, connection, 'write'));
|
const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
|
||||||
|
|
||||||
|
try {
|
||||||
logger.info(`Connected.`);
|
logger.info(`Connected.`);
|
||||||
return await driver.writeTable(pool, { schemaName, pureName }, options);
|
return await driver.writeTable(dbhan, { schemaName, pureName }, options);
|
||||||
|
} finally {
|
||||||
|
if (!systemConnection) {
|
||||||
|
await driver.close(dbhan);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = tableWriter;
|
module.exports = tableWriter;
|
||||||
|
|||||||
Reference in New Issue
Block a user