mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 06:46:00 +00:00
mongo sorts - moved to plugin
This commit is contained in:
@@ -7,7 +7,11 @@ const MongoClient = require('mongodb').MongoClient;
|
||||
const ObjectId = require('mongodb').ObjectId;
|
||||
const AbstractCursor = require('mongodb').AbstractCursor;
|
||||
const createBulkInsertStream = require('./createBulkInsertStream');
|
||||
const { convertToMongoCondition, convertToMongoAggregate } = require('../frontend/convertToMongoCondition');
|
||||
const {
|
||||
convertToMongoCondition,
|
||||
convertToMongoAggregate,
|
||||
convertToMongoSort,
|
||||
} = require('../frontend/convertToMongoCondition');
|
||||
|
||||
function transformMongoData(row) {
|
||||
return _.cloneDeepWith(row, (x) => {
|
||||
@@ -286,7 +290,7 @@ const driver = {
|
||||
} else {
|
||||
// console.log('options.condition', JSON.stringify(options.condition, undefined, 2));
|
||||
let cursor = await collection.find(convertObjectId(mongoCondition) || {});
|
||||
if (options.sort) cursor = cursor.sort(options.sort);
|
||||
if (options.sort) cursor = cursor.sort(convertToMongoSort(options.sort));
|
||||
if (options.skip) cursor = cursor.skip(options.skip);
|
||||
if (options.limit) cursor = cursor.limit(options.limit);
|
||||
const rows = await cursor.toArray();
|
||||
|
||||
@@ -171,7 +171,16 @@ function convertToMongoAggregate(collectionAggregate) {
|
||||
];
|
||||
}
|
||||
|
||||
function convertToMongoSort(sort) {
|
||||
if (!sort) return null;
|
||||
return _zipObject(
|
||||
sort.map((col) => col.columnName),
|
||||
sort.map((col) => (col.order == 'DESC' ? -1 : 1))
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
convertToMongoCondition,
|
||||
convertToMongoAggregate,
|
||||
convertToMongoSort,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const { driverBase } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||
const { convertToMongoCondition } = require('./convertToMongoCondition');
|
||||
const { convertToMongoCondition, convertToMongoSort } = require('./convertToMongoCondition');
|
||||
const Dumper = require('./Dumper');
|
||||
const { mongoSplitterOptions } = require('dbgate-query-splitter/lib/options');
|
||||
|
||||
@@ -101,14 +101,14 @@ const driver = {
|
||||
|
||||
getCollectionExportQueryScript(collection, condition, sort) {
|
||||
return `db.collection('${collection}')
|
||||
.find(${JSON.stringify(convertToMongoCondition(condition || {}))})
|
||||
.sort(${JSON.stringify(sort || {})})`;
|
||||
.find(${JSON.stringify(convertToMongoCondition(condition) || {})})
|
||||
.sort(${JSON.stringify(convertToMongoSort(sort) || {})})`;
|
||||
},
|
||||
getCollectionExportQueryJson(collection, condition, sort) {
|
||||
return {
|
||||
collection,
|
||||
condition: convertToMongoCondition(condition || {}),
|
||||
sort: sort || {},
|
||||
condition: convertToMongoCondition(condition) || {},
|
||||
sort: convertToMongoSort(sort) || {},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user