mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 10:36:00 +00:00
SYNC: Merge branch 'feature/mongosh'
This commit is contained in:
committed by
Diflow
parent
01ee66ec4f
commit
9230a2ab73
@@ -1,4 +1,5 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const { EventEmitter } = require('events');
|
||||||
const stream = require('stream');
|
const stream = require('stream');
|
||||||
const driverBase = require('../frontend/driver');
|
const driverBase = require('../frontend/driver');
|
||||||
const Analyser = require('./Analyser');
|
const Analyser = require('./Analyser');
|
||||||
@@ -58,27 +59,26 @@ async function getScriptableDb(dbhan) {
|
|||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @param {string} uri
|
// * @param {string} uri
|
||||||
* @param {string} dbName
|
// * @param {string} dbName
|
||||||
* @returns {string}
|
// * @returns {string}
|
||||||
*/
|
// */
|
||||||
function ensureDatabaseInMongoURI(uri, dbName) {
|
// function ensureDatabaseInMongoURI(uri, dbName) {
|
||||||
if (!dbName) return uri;
|
// if (!dbName) return uri;
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
const url = new URL(uri);
|
// const url = new URL(uri);
|
||||||
|
|
||||||
const hasDatabase = url.pathname && url.pathname !== '/' && url.pathname.length > 1;
|
// const hasDatabase = url.pathname && url.pathname !== '/' && url.pathname.length > 1;
|
||||||
if (hasDatabase) return uri;
|
// if (hasDatabase) return uri;
|
||||||
|
// url.pathname = `/${dbName}`;
|
||||||
url.pathname = `/${dbName}`;
|
// return url.toString();
|
||||||
return url.toString();
|
// } catch (error) {
|
||||||
} catch (error) {
|
// logger.error('DBGM-00198 Invalid URI format:', error.message);
|
||||||
logger.error('DBGM-00198 Invalid URI format:', error.message);
|
// return uri;
|
||||||
return uri;
|
// }
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
/** @type {import('dbgate-types').EngineDriver<MongoClient>} */
|
/** @type {import('dbgate-types').EngineDriver<MongoClient>} */
|
||||||
const driver = {
|
const driver = {
|
||||||
@@ -119,6 +119,7 @@ const driver = {
|
|||||||
return {
|
return {
|
||||||
client,
|
client,
|
||||||
database,
|
database,
|
||||||
|
// mongoUrl,
|
||||||
getDatabase: database ? () => client.db(database) : () => client.db(),
|
getDatabase: database ? () => client.db(database) : () => client.db(),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -192,9 +193,9 @@ const driver = {
|
|||||||
let exprValue;
|
let exprValue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const connectionString = ensureDatabaseInMongoURI(dbhan.client.s.url, dbhan.database);
|
const serviceProvider = new NodeDriverServiceProvider(dbhan.client, new EventEmitter(), { productDocsLink: '', productName: 'DbGate' });
|
||||||
const serviceProvider = await NodeDriverServiceProvider.connect(connectionString);
|
|
||||||
const runtime = new ElectronRuntime(serviceProvider);
|
const runtime = new ElectronRuntime(serviceProvider);
|
||||||
|
await runtime.evaluate(`use ${dbhan.database}`);
|
||||||
exprValue = await runtime.evaluate(sql);
|
exprValue = await runtime.evaluate(sql);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
options.info({
|
options.info({
|
||||||
@@ -208,6 +209,25 @@ const driver = {
|
|||||||
|
|
||||||
const { printable, type } = exprValue;
|
const { printable, type } = exprValue;
|
||||||
|
|
||||||
|
if (typeof printable === 'string') {
|
||||||
|
options.info({
|
||||||
|
time: new Date(),
|
||||||
|
severity: 'info',
|
||||||
|
message: printable,
|
||||||
|
});
|
||||||
|
options.done();
|
||||||
|
return;
|
||||||
|
} else if (typeof printable !== 'object' || printable === null) {
|
||||||
|
options.info({
|
||||||
|
printable: printable,
|
||||||
|
time: new Date(),
|
||||||
|
severity: 'info',
|
||||||
|
message: 'Query returned not supported value.',
|
||||||
|
});
|
||||||
|
options.done();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (type === 'Document') {
|
if (type === 'Document') {
|
||||||
options.recordset({ __isDynamicStructure: true });
|
options.recordset({ __isDynamicStructure: true });
|
||||||
options.row(printable);
|
options.row(printable);
|
||||||
|
|||||||
Reference in New Issue
Block a user