mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 19:56:00 +00:00
perspectives: support nosql other than mongo
This commit is contained in:
@@ -123,7 +123,7 @@ export class PerspectiveDataLoader {
|
||||
groupByColumns: bindingColumns,
|
||||
aggregateColumns: [
|
||||
{
|
||||
alias: 'acount',
|
||||
alias: 'pergrpsize',
|
||||
aggregateFunction: 'count',
|
||||
},
|
||||
],
|
||||
@@ -156,8 +156,8 @@ export class PerspectiveDataLoader {
|
||||
|
||||
if (response.errorMessage) return response;
|
||||
return response.rows.map(row => ({
|
||||
...row._id,
|
||||
_perspective_group_size_: parseInt(row.count),
|
||||
...row,
|
||||
_perspective_group_size_: parseInt(row.pergrpsize),
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -463,6 +463,8 @@ export abstract class PerspectiveTreeNode {
|
||||
order: 'ASC' as 'ASC',
|
||||
}));
|
||||
if (pkColumns) return pkColumns;
|
||||
const uqColumns = (table as CollectionInfo)?.uniqueKey;
|
||||
if (uqColumns?.length >= 1) return uqColumns.map(x => ({ columnName: x.columnName, order: 'ASC' }));
|
||||
const columns = (table as TableInfo | ViewInfo)?.columns;
|
||||
if (columns) return [{ columnName: columns[0].columnName, order: 'ASC' }];
|
||||
return [{ columnName: '_id', order: 'ASC' }];
|
||||
|
||||
@@ -305,7 +305,12 @@ const driver = {
|
||||
} else if (options.aggregate) {
|
||||
let cursor = await collection.aggregate(convertObjectId(convertToMongoAggregate(options.aggregate)));
|
||||
const rows = await cursor.toArray();
|
||||
return { rows: rows.map(transformMongoData) };
|
||||
return {
|
||||
rows: rows.map(transformMongoData).map((x) => ({
|
||||
...x._id,
|
||||
..._.omit(x, ['_id']),
|
||||
})),
|
||||
};
|
||||
} else {
|
||||
// console.log('options.condition', JSON.stringify(options.condition, undefined, 2));
|
||||
let cursor = await collection.find(convertObjectId(mongoCondition) || {});
|
||||
@@ -313,7 +318,9 @@ const driver = {
|
||||
if (options.skip) cursor = cursor.skip(options.skip);
|
||||
if (options.limit) cursor = cursor.limit(options.limit);
|
||||
const rows = await cursor.toArray();
|
||||
return { rows: rows.map(transformMongoData) };
|
||||
return {
|
||||
rows: rows.map(transformMongoData),
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
return { errorMessage: err.message };
|
||||
|
||||
Reference in New Issue
Block a user