mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 10:53:57 +00:00
mongo sorts - moved to plugin
This commit is contained in:
@@ -238,15 +238,16 @@ export class PerspectiveDataLoader {
|
||||
const res: any = {
|
||||
pureName,
|
||||
condition: this.buildSqlCondition(props),
|
||||
sort: useSort ? props.orderBy : undefined,
|
||||
skip: props.range?.offset,
|
||||
limit: props.range?.limit,
|
||||
};
|
||||
if (useSort && props.orderBy?.length > 0) {
|
||||
res.sort = _zipObject(
|
||||
props.orderBy.map(col => col.columnName),
|
||||
props.orderBy.map(col => (col.order == 'DESC' ? -1 : 1))
|
||||
);
|
||||
}
|
||||
// if (useSort && props.orderBy?.length > 0) {
|
||||
// res.sort = _zipObject(
|
||||
// props.orderBy.map(col => col.columnName),
|
||||
// props.orderBy.map(col => (col.order == 'DESC' ? -1 : 1))
|
||||
// );
|
||||
// }
|
||||
|
||||
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;
|
||||
condition?: any;
|
||||
aggregate?: CollectionAggregateDefinition;
|
||||
sort?: CollectionSortDefinition;
|
||||
}
|
||||
|
||||
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 {
|
||||
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 }>;
|
||||
getAuthTokenFromCode(connection, options): Promise<string>;
|
||||
getAccessTokenFromAuth(connection, req): Promise<string | null>;
|
||||
getCollectionExportQueryScript(collection: string, condition: any, sort: any): string;
|
||||
getCollectionExportQueryJson(collection: string, condition: any, sort: any): {};
|
||||
getCollectionExportQueryScript(collection: string, condition: any, sort?: CollectionSortDefinition): string;
|
||||
getCollectionExportQueryJson(collection: string, condition: any, sort?: CollectionSortDefinition): {};
|
||||
|
||||
analyserClass?: any;
|
||||
dumperClass?: any;
|
||||
|
||||
@@ -60,14 +60,14 @@
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function buildMongoSort(props) {
|
||||
function buildSortForGrid(props) {
|
||||
const sort = props?.display?.config?.sort;
|
||||
|
||||
if (sort?.length > 0) {
|
||||
return _.zipObject(
|
||||
sort.map(col => col.uniqueName),
|
||||
sort.map(col => (col.order == 'DESC' ? -1 : 1))
|
||||
);
|
||||
return sort.map(col => ({
|
||||
columnName: col.uniqueName,
|
||||
order: col.order,
|
||||
}));
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -84,7 +84,7 @@
|
||||
limit,
|
||||
skip: offset,
|
||||
condition: buildConditionForGrid(props),
|
||||
sort: buildMongoSort(props),
|
||||
sort: buildSortForGrid(props),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -175,7 +175,7 @@
|
||||
return display?.driver?.getCollectionExportQueryScript?.(
|
||||
pureName,
|
||||
buildConditionForGrid($$props),
|
||||
buildMongoSort($$props)
|
||||
buildSortForGrid($$props)
|
||||
);
|
||||
// return `db.collection('${pureName}')
|
||||
// .find(${JSON.stringify(buildConditionForGrid($$props) || {})})
|
||||
@@ -186,7 +186,7 @@
|
||||
return display?.driver?.getCollectionExportQueryJson?.(
|
||||
pureName,
|
||||
buildConditionForGrid($$props),
|
||||
buildMongoSort($$props)
|
||||
buildSortForGrid($$props)
|
||||
);
|
||||
// return {
|
||||
// collection: pureName,
|
||||
|
||||
Reference in New Issue
Block a user