mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 00:56:02 +00:00
SYNC: mongosh - use only in stream method
This commit is contained in:
committed by
Diflow
parent
7ec9fb2c44
commit
56ca1911a1
@@ -130,33 +130,33 @@ const driver = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
async script(dbhan, sql) {
|
async script(dbhan, sql) {
|
||||||
if (isProApp) {
|
// MongoSH should be used only in stream method
|
||||||
const { NodeDriverServiceProvider } = require('@mongosh/service-provider-node-driver');
|
// if (isProApp) {
|
||||||
const { ElectronRuntime } = require('@mongosh/browser-runtime-electron');
|
// const { NodeDriverServiceProvider } = require('@mongosh/service-provider-node-driver');
|
||||||
|
// const { ElectronRuntime } = require('@mongosh/browser-runtime-electron');
|
||||||
|
|
||||||
const connectionString = ensureDatabaseInMongoURI(dbhan.client.s.url, dbhan.database);
|
// const connectionString = ensureDatabaseInMongoURI(dbhan.client.s.url, dbhan.database);
|
||||||
const serviceProvider = await NodeDriverServiceProvider.connect(connectionString);
|
// const serviceProvider = await NodeDriverServiceProvider.connect(connectionString);
|
||||||
const runtime = new ElectronRuntime(serviceProvider);
|
// const runtime = new ElectronRuntime(serviceProvider);
|
||||||
const exprValue = await runtime.evaluate(sql);
|
// const exprValue = await runtime.evaluate(sql);
|
||||||
|
|
||||||
const { printable } = exprValue;
|
// const { printable } = exprValue;
|
||||||
|
|
||||||
if (Array.isArray(printable)) {
|
// if (Array.isArray(printable)) {
|
||||||
return printable;
|
// return printable;
|
||||||
} else if ('documents' in printable) {
|
// } else if ('documents' in printable) {
|
||||||
return printable.documents;
|
// return printable.documents;
|
||||||
} else if ('cursor' in printable && 'firstBatch' in printable.cursor) {
|
// } else if ('cursor' in printable && 'firstBatch' in printable.cursor) {
|
||||||
return printable.cursor.firstBatch;
|
// return printable.cursor.firstBatch;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return printable;
|
// return printable;
|
||||||
} else {
|
// }
|
||||||
let func;
|
let func;
|
||||||
func = eval(`(db,ObjectId) => ${sql}`);
|
func = eval(`(db,ObjectId) => ${sql}`);
|
||||||
const db = await getScriptableDb(dbhan);
|
const db = await getScriptableDb(dbhan);
|
||||||
const res = func(db, ObjectId.createFromHexString);
|
const res = func(db, ObjectId.createFromHexString);
|
||||||
if (isPromise(res)) await res;
|
if (isPromise(res)) await res;
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async operation(dbhan, operation, options) {
|
async operation(dbhan, operation, options) {
|
||||||
const { type } = operation;
|
const { type } = operation;
|
||||||
|
|||||||
Reference in New Issue
Block a user