diff --git a/packages/datalib/src/CollectionGridDisplay.ts b/packages/datalib/src/CollectionGridDisplay.ts index 572341c8..1a7d6e1f 100644 --- a/packages/datalib/src/CollectionGridDisplay.ts +++ b/packages/datalib/src/CollectionGridDisplay.ts @@ -66,6 +66,10 @@ function getDisplayColumn(basePath, columnName, display: CollectionGridDisplay) filterBehaviour: display?.driver?.getFilterBehaviour(null, standardFilterBehaviours) ?? mongoFilterBehaviour, pureName: display.collection?.pureName, schemaName: display.collection?.schemaName, + + isPartitionKey: !!display?.collection?.partitionKey?.find(x => x.columnName == uniqueName), + isClusterKey: !!display?.collection?.clusterKey?.find(x => x.columnName == uniqueName), + isUniqueKey: !!display?.collection?.uniqueKey?.find(x => x.columnName == uniqueName), }; } @@ -105,10 +109,10 @@ export class CollectionGridDisplay extends GridDisplay { this.columns = analyseCollectionDisplayColumns([...(loadedRows || []), ...changedDocs, ...insertedDocs], this); this.filterable = true; this.sortable = true; - this.editable = !readOnly; + this.editable = !readOnly && collection.uniqueKey?.length > 0; this.supportsReload = true; this.isDynamicStructure = true; - this.changeSetKeyFields = ['_id']; + this.changeSetKeyFields = collection.uniqueKey?.map(x => x.columnName); this.baseCollection = collection; } } diff --git a/packages/datalib/src/GridDisplay.ts b/packages/datalib/src/GridDisplay.ts index 5b4d49a7..3ea5c1ff 100644 --- a/packages/datalib/src/GridDisplay.ts +++ b/packages/datalib/src/GridDisplay.ts @@ -28,6 +28,12 @@ export interface DisplayColumn { notNull?: boolean; autoIncrement?: boolean; isPrimaryKey?: boolean; + + // NoSQL specific + isPartitionKey?: boolean; + isClusterKey?: boolean; + isUniqueKey?: boolean; + foreignKey?: ForeignKeyInfo; isForeignKeyUnique?: boolean; isExpandable?: boolean; diff --git a/packages/web/src/datagrid/DataGridCore.svelte b/packages/web/src/datagrid/DataGridCore.svelte index 486a1097..ec51a266 100644 --- a/packages/web/src/datagrid/DataGridCore.svelte +++ b/packages/web/src/datagrid/DataGridCore.svelte @@ -559,7 +559,7 @@ for (const column of display.columns) { if (column.uniquePath.length > 1) continue; if (column.autoIncrement) continue; - if (column.columnName == '_id' && isDynamicStructure) continue; + if (column.isClusterKey) continue; grider.setCellValue(rowIndex, column.uniqueName, grider.getRowData(index)[column.uniqueName]); } @@ -959,7 +959,9 @@ export async function mergeSelectionIntoMirror({ fullRows, mergeMode = 'merge' }) { const file = display.baseTableOrSimilar?.pureName; - const mergeKey = display.baseCollection ? ['_id'] : display.baseTable?.primaryKey.columns.map(x => x.columnName); + const mergeKey = display.baseCollection + ? display.baseCollection?.uniqueKey?.map(x => x.columnName) + : display.baseTable?.primaryKey.columns.map(x => x.columnName); const cells = cellsToRegularCells(selectedCells); const rowIndexes = _.sortBy(_.uniq(cells.map(x => x[0]))); diff --git a/plugins/dbgate-plugin-mongo/src/backend/Analyser.js b/plugins/dbgate-plugin-mongo/src/backend/Analyser.js index 88843f0f..0e4a80fb 100644 --- a/plugins/dbgate-plugin-mongo/src/backend/Analyser.js +++ b/plugins/dbgate-plugin-mongo/src/backend/Analyser.js @@ -35,10 +35,14 @@ class Analyser extends DatabaseAnalyser { pureName: x.name, tableRowCount: stats[index]?.count, uniqueKey: [{ columnName: '_id' }], + partitionKey: [{ columnName: '_id' }], + clusterKey: [{ columnName: '_id' }], })), ...views.map((x, index) => ({ pureName: x.name, uniqueKey: [{ columnName: '_id' }], + partitionKey: [{ columnName: '_id' }], + clusterKey: [{ columnName: '_id' }], })), ], });