mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 18:34:01 +00:00
mongo sorts - moved to plugin
This commit is contained in:
@@ -238,15 +238,16 @@ export class PerspectiveDataLoader {
|
|||||||
const res: any = {
|
const res: any = {
|
||||||
pureName,
|
pureName,
|
||||||
condition: this.buildSqlCondition(props),
|
condition: this.buildSqlCondition(props),
|
||||||
|
sort: useSort ? props.orderBy : undefined,
|
||||||
skip: props.range?.offset,
|
skip: props.range?.offset,
|
||||||
limit: props.range?.limit,
|
limit: props.range?.limit,
|
||||||
};
|
};
|
||||||
if (useSort && props.orderBy?.length > 0) {
|
// if (useSort && props.orderBy?.length > 0) {
|
||||||
res.sort = _zipObject(
|
// res.sort = _zipObject(
|
||||||
props.orderBy.map(col => col.columnName),
|
// props.orderBy.map(col => col.columnName),
|
||||||
props.orderBy.map(col => (col.order == 'DESC' ? -1 : 1))
|
// props.orderBy.map(col => (col.order == 'DESC' ? -1 : 1))
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
12
packages/types/engines.d.ts
vendored
12
packages/types/engines.d.ts
vendored
@@ -43,6 +43,7 @@ export interface ReadCollectionOptions {
|
|||||||
limit?: number;
|
limit?: number;
|
||||||
condition?: any;
|
condition?: any;
|
||||||
aggregate?: CollectionAggregateDefinition;
|
aggregate?: CollectionAggregateDefinition;
|
||||||
|
sort?: CollectionSortDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NewObjectTemplate {
|
export interface NewObjectTemplate {
|
||||||
@@ -85,6 +86,13 @@ export interface CollectionAggregateDefinition {
|
|||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CollectionSortDefinitionItem {
|
||||||
|
columnName: string;
|
||||||
|
direction: 'ASC' | 'DESC';
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CollectionSortDefinition = CollectionSortDefinitionItem[];
|
||||||
|
|
||||||
export interface FilterBehaviourProvider {
|
export interface FilterBehaviourProvider {
|
||||||
getFilterBehaviour(dataType: string, standardFilterBehaviours: { [id: string]: FilterBehaviour }): FilterBehaviour;
|
getFilterBehaviour(dataType: string, standardFilterBehaviours: { [id: string]: FilterBehaviour }): FilterBehaviour;
|
||||||
}
|
}
|
||||||
@@ -171,8 +179,8 @@ export interface EngineDriver extends FilterBehaviourProvider {
|
|||||||
getRedirectAuthUrl(connection, options): Promise<{ url: string; sid: string }>;
|
getRedirectAuthUrl(connection, options): Promise<{ url: string; sid: string }>;
|
||||||
getAuthTokenFromCode(connection, options): Promise<string>;
|
getAuthTokenFromCode(connection, options): Promise<string>;
|
||||||
getAccessTokenFromAuth(connection, req): Promise<string | null>;
|
getAccessTokenFromAuth(connection, req): Promise<string | null>;
|
||||||
getCollectionExportQueryScript(collection: string, condition: any, sort: any): string;
|
getCollectionExportQueryScript(collection: string, condition: any, sort?: CollectionSortDefinition): string;
|
||||||
getCollectionExportQueryJson(collection: string, condition: any, sort: any): {};
|
getCollectionExportQueryJson(collection: string, condition: any, sort?: CollectionSortDefinition): {};
|
||||||
|
|
||||||
analyserClass?: any;
|
analyserClass?: any;
|
||||||
dumperClass?: any;
|
dumperClass?: any;
|
||||||
|
|||||||
@@ -60,14 +60,14 @@
|
|||||||
: undefined;
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildMongoSort(props) {
|
function buildSortForGrid(props) {
|
||||||
const sort = props?.display?.config?.sort;
|
const sort = props?.display?.config?.sort;
|
||||||
|
|
||||||
if (sort?.length > 0) {
|
if (sort?.length > 0) {
|
||||||
return _.zipObject(
|
return sort.map(col => ({
|
||||||
sort.map(col => col.uniqueName),
|
columnName: col.uniqueName,
|
||||||
sort.map(col => (col.order == 'DESC' ? -1 : 1))
|
order: col.order,
|
||||||
);
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -84,7 +84,7 @@
|
|||||||
limit,
|
limit,
|
||||||
skip: offset,
|
skip: offset,
|
||||||
condition: buildConditionForGrid(props),
|
condition: buildConditionForGrid(props),
|
||||||
sort: buildMongoSort(props),
|
sort: buildSortForGrid(props),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@
|
|||||||
return display?.driver?.getCollectionExportQueryScript?.(
|
return display?.driver?.getCollectionExportQueryScript?.(
|
||||||
pureName,
|
pureName,
|
||||||
buildConditionForGrid($$props),
|
buildConditionForGrid($$props),
|
||||||
buildMongoSort($$props)
|
buildSortForGrid($$props)
|
||||||
);
|
);
|
||||||
// return `db.collection('${pureName}')
|
// return `db.collection('${pureName}')
|
||||||
// .find(${JSON.stringify(buildConditionForGrid($$props) || {})})
|
// .find(${JSON.stringify(buildConditionForGrid($$props) || {})})
|
||||||
@@ -186,7 +186,7 @@
|
|||||||
return display?.driver?.getCollectionExportQueryJson?.(
|
return display?.driver?.getCollectionExportQueryJson?.(
|
||||||
pureName,
|
pureName,
|
||||||
buildConditionForGrid($$props),
|
buildConditionForGrid($$props),
|
||||||
buildMongoSort($$props)
|
buildSortForGrid($$props)
|
||||||
);
|
);
|
||||||
// return {
|
// return {
|
||||||
// collection: pureName,
|
// collection: pureName,
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ const MongoClient = require('mongodb').MongoClient;
|
|||||||
const ObjectId = require('mongodb').ObjectId;
|
const ObjectId = require('mongodb').ObjectId;
|
||||||
const AbstractCursor = require('mongodb').AbstractCursor;
|
const AbstractCursor = require('mongodb').AbstractCursor;
|
||||||
const createBulkInsertStream = require('./createBulkInsertStream');
|
const createBulkInsertStream = require('./createBulkInsertStream');
|
||||||
const { convertToMongoCondition, convertToMongoAggregate } = require('../frontend/convertToMongoCondition');
|
const {
|
||||||
|
convertToMongoCondition,
|
||||||
|
convertToMongoAggregate,
|
||||||
|
convertToMongoSort,
|
||||||
|
} = require('../frontend/convertToMongoCondition');
|
||||||
|
|
||||||
function transformMongoData(row) {
|
function transformMongoData(row) {
|
||||||
return _.cloneDeepWith(row, (x) => {
|
return _.cloneDeepWith(row, (x) => {
|
||||||
@@ -286,7 +290,7 @@ const driver = {
|
|||||||
} else {
|
} else {
|
||||||
// console.log('options.condition', JSON.stringify(options.condition, undefined, 2));
|
// console.log('options.condition', JSON.stringify(options.condition, undefined, 2));
|
||||||
let cursor = await collection.find(convertObjectId(mongoCondition) || {});
|
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.skip) cursor = cursor.skip(options.skip);
|
||||||
if (options.limit) cursor = cursor.limit(options.limit);
|
if (options.limit) cursor = cursor.limit(options.limit);
|
||||||
const rows = await cursor.toArray();
|
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 = {
|
module.exports = {
|
||||||
convertToMongoCondition,
|
convertToMongoCondition,
|
||||||
convertToMongoAggregate,
|
convertToMongoAggregate,
|
||||||
|
convertToMongoSort,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const { driverBase } = global.DBGATE_PACKAGES['dbgate-tools'];
|
const { driverBase } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||||
const { convertToMongoCondition } = require('./convertToMongoCondition');
|
const { convertToMongoCondition, convertToMongoSort } = require('./convertToMongoCondition');
|
||||||
const Dumper = require('./Dumper');
|
const Dumper = require('./Dumper');
|
||||||
const { mongoSplitterOptions } = require('dbgate-query-splitter/lib/options');
|
const { mongoSplitterOptions } = require('dbgate-query-splitter/lib/options');
|
||||||
|
|
||||||
@@ -101,14 +101,14 @@ const driver = {
|
|||||||
|
|
||||||
getCollectionExportQueryScript(collection, condition, sort) {
|
getCollectionExportQueryScript(collection, condition, sort) {
|
||||||
return `db.collection('${collection}')
|
return `db.collection('${collection}')
|
||||||
.find(${JSON.stringify(convertToMongoCondition(condition || {}))})
|
.find(${JSON.stringify(convertToMongoCondition(condition) || {})})
|
||||||
.sort(${JSON.stringify(sort || {})})`;
|
.sort(${JSON.stringify(convertToMongoSort(sort) || {})})`;
|
||||||
},
|
},
|
||||||
getCollectionExportQueryJson(collection, condition, sort) {
|
getCollectionExportQueryJson(collection, condition, sort) {
|
||||||
return {
|
return {
|
||||||
collection,
|
collection,
|
||||||
condition: convertToMongoCondition(condition || {}),
|
condition: convertToMongoCondition(condition) || {},
|
||||||
sort: sort || {},
|
sort: convertToMongoSort(sort) || {},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user