mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 13:53:59 +00:00
createDb, dropDb - catch errors
This commit is contained in:
@@ -59,7 +59,7 @@ module.exports = {
|
|||||||
if (connection.useRedirectDbLogin) {
|
if (connection.useRedirectDbLogin) {
|
||||||
throw new MissingCredentialsError({ conid, redirectToDbLogin: true });
|
throw new MissingCredentialsError({ conid, redirectToDbLogin: true });
|
||||||
}
|
}
|
||||||
const subprocess = fork(
|
const subprocess = fork(
|
||||||
global['API_PACKAGE'] || process.argv[1],
|
global['API_PACKAGE'] || process.argv[1],
|
||||||
[
|
[
|
||||||
'--is-forked-api',
|
'--is-forked-api',
|
||||||
@@ -184,22 +184,29 @@ module.exports = {
|
|||||||
return { status: 'ok' };
|
return { status: 'ok' };
|
||||||
},
|
},
|
||||||
|
|
||||||
createDatabase_meta: true,
|
async sendDatabaseOp({ conid, msgtype, name }, req) {
|
||||||
async createDatabase({ conid, name }, req) {
|
|
||||||
testConnectionPermission(conid, req);
|
testConnectionPermission(conid, req);
|
||||||
const opened = await this.ensureOpened(conid);
|
const opened = await this.ensureOpened(conid);
|
||||||
if (opened.connection.isReadOnly) return false;
|
if (opened.connection.isReadOnly) return false;
|
||||||
opened.subprocess.send({ msgtype: 'createDatabase', name });
|
const res = await this.sendRequest(opened, { msgtype, name });
|
||||||
return { status: 'ok' };
|
if (res.errorMessage) {
|
||||||
|
console.error(res.errorMessage);
|
||||||
|
|
||||||
|
return {
|
||||||
|
apiErrorMessage: res.errorMessage,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return res.result || null;
|
||||||
|
},
|
||||||
|
|
||||||
|
createDatabase_meta: true,
|
||||||
|
async createDatabase({ conid, name }, req) {
|
||||||
|
return this.sendDatabaseOp({ conid, msgtype: 'createDatabase', name }, req);
|
||||||
},
|
},
|
||||||
|
|
||||||
dropDatabase_meta: true,
|
dropDatabase_meta: true,
|
||||||
async dropDatabase({ conid, name }, req) {
|
async dropDatabase({ conid, name }, req) {
|
||||||
testConnectionPermission(conid, req);
|
return this.sendDatabaseOp({ conid, msgtype: 'dropDatabase', name }, req);
|
||||||
const opened = await this.ensureOpened(conid);
|
|
||||||
if (opened.connection.isReadOnly) return false;
|
|
||||||
opened.subprocess.send({ msgtype: 'dropDatabase', name });
|
|
||||||
return { status: 'ok' };
|
|
||||||
},
|
},
|
||||||
|
|
||||||
sendRequest(conn, message) {
|
sendRequest(conn, message) {
|
||||||
|
|||||||
@@ -105,18 +105,24 @@ function handlePing() {
|
|||||||
lastPing = new Date().getTime();
|
lastPing = new Date().getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleDatabaseOp(op, { name }) {
|
async function handleDatabaseOp(op, { msgid, name }) {
|
||||||
const driver = requireEngineDriver(storedConnection);
|
try {
|
||||||
systemConnection = await connectUtility(driver, storedConnection, 'app');
|
const driver = requireEngineDriver(storedConnection);
|
||||||
if (driver[op]) {
|
systemConnection = await connectUtility(driver, storedConnection, 'app');
|
||||||
await driver[op](systemConnection, name);
|
if (driver[op]) {
|
||||||
} else {
|
await driver[op](systemConnection, name);
|
||||||
const dmp = driver.createDumper();
|
} else {
|
||||||
dmp[op](name);
|
const dmp = driver.createDumper();
|
||||||
logger.info({ sql: dmp.s }, 'Running script');
|
dmp[op](name);
|
||||||
await driver.query(systemConnection, dmp.s);
|
logger.info({ sql: dmp.s }, 'Running script');
|
||||||
|
await driver.query(systemConnection, dmp.s);
|
||||||
|
}
|
||||||
|
await handleRefresh();
|
||||||
|
|
||||||
|
process.send({ msgtype: 'response', msgid, status: 'ok' });
|
||||||
|
} catch (err) {
|
||||||
|
process.send({ msgtype: 'response', msgid, errorMessage: err.message });
|
||||||
}
|
}
|
||||||
await handleRefresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleDriverDataCore(msgid, callMethod) {
|
async function handleDriverDataCore(msgid, callMethod) {
|
||||||
|
|||||||
@@ -96,18 +96,10 @@ const driver = {
|
|||||||
columns: [],
|
columns: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
//console.log('sql3', sql);
|
const res = await client.execute(sql);
|
||||||
const res = await client.execute(sql);
|
const columns = extractOracleColumns(res.metaData);
|
||||||
//console.log('res', res);
|
return { rows: (res.rows || []).map(row => zipDataRow(row, columns)), columns };
|
||||||
const columns = extractOracleColumns(res.metaData);
|
|
||||||
//console.log('columns', columns);
|
|
||||||
return { rows: (res.rows || []).map(row => zipDataRow(row, columns)), columns };
|
|
||||||
} catch (err) {
|
|
||||||
console.log('Error query', err, sql);
|
|
||||||
} finally {
|
|
||||||
//console.log('finally', sql);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
stream(client, sql, options) {
|
stream(client, sql, options) {
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user