mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 04:26:01 +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) {
|
||||
if (isProApp) {
|
||||
const { NodeDriverServiceProvider } = require('@mongosh/service-provider-node-driver');
|
||||
const { ElectronRuntime } = require('@mongosh/browser-runtime-electron');
|
||||
// MongoSH should be used only in stream method
|
||||
// if (isProApp) {
|
||||
// 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 serviceProvider = await NodeDriverServiceProvider.connect(connectionString);
|
||||
const runtime = new ElectronRuntime(serviceProvider);
|
||||
const exprValue = await runtime.evaluate(sql);
|
||||
// const connectionString = ensureDatabaseInMongoURI(dbhan.client.s.url, dbhan.database);
|
||||
// const serviceProvider = await NodeDriverServiceProvider.connect(connectionString);
|
||||
// const runtime = new ElectronRuntime(serviceProvider);
|
||||
// const exprValue = await runtime.evaluate(sql);
|
||||
|
||||
const { printable } = exprValue;
|
||||
// const { printable } = exprValue;
|
||||
|
||||
if (Array.isArray(printable)) {
|
||||
return printable;
|
||||
} else if ('documents' in printable) {
|
||||
return printable.documents;
|
||||
} else if ('cursor' in printable && 'firstBatch' in printable.cursor) {
|
||||
return printable.cursor.firstBatch;
|
||||
}
|
||||
// if (Array.isArray(printable)) {
|
||||
// return printable;
|
||||
// } else if ('documents' in printable) {
|
||||
// return printable.documents;
|
||||
// } else if ('cursor' in printable && 'firstBatch' in printable.cursor) {
|
||||
// return printable.cursor.firstBatch;
|
||||
// }
|
||||
|
||||
return printable;
|
||||
} else {
|
||||
let func;
|
||||
func = eval(`(db,ObjectId) => ${sql}`);
|
||||
const db = await getScriptableDb(dbhan);
|
||||
const res = func(db, ObjectId.createFromHexString);
|
||||
if (isPromise(res)) await res;
|
||||
}
|
||||
// return printable;
|
||||
// }
|
||||
let func;
|
||||
func = eval(`(db,ObjectId) => ${sql}`);
|
||||
const db = await getScriptableDb(dbhan);
|
||||
const res = func(db, ObjectId.createFromHexString);
|
||||
if (isPromise(res)) await res;
|
||||
},
|
||||
async operation(dbhan, operation, options) {
|
||||
const { type } = operation;
|
||||
|
||||
Reference in New Issue
Block a user