Browse Source

feat: add the update functionality

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5848/head
Pranav C 2 years ago
parent
commit
7dc8ad4aaa
  1. 26
      packages/nocodb/src/models/Column.ts
  2. 22
      packages/nocodb/src/services/columns.service.ts

26
packages/nocodb/src/models/Column.ts

@ -10,6 +10,7 @@ import Noco from '../Noco';
import addFormulaErrorIfMissingColumn from '../helpers/addFormulaErrorIfMissingColumn';
import { NcError } from '../helpers/catchError';
import { extractProps } from '../helpers/extractProps';
import { stringifyMetaProp } from '../utils/modelUtils';
import FormulaColumn from './FormulaColumn';
import LinkToAnotherRecordColumn from './LinkToAnotherRecordColumn';
import LookupColumn from './LookupColumn';
@ -1207,4 +1208,29 @@ export default class Column<T = any> implements ColumnType {
}
return fieldLengthLimit;
}
static async updateMeta(
{ colId, meta }: { colId: string; meta: any },
ncMeta = Noco.ncMeta,
) {
// get existing cache
const key = `${CacheScope.COLUMN}:${colId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update meta
o.meta = meta;
// set cache
await NocoCache.set(key, o);
}
// set meta
await ncMeta.metaUpdate(
null,
null,
MetaTable.COLUMNS,
{
meta: stringifyMetaProp(meta),
},
colId,
);
}
}

22
packages/nocodb/src/services/columns.service.ts

@ -41,10 +41,7 @@ import Noco from '../Noco';
import NcConnectionMgrv2 from '../utils/common/NcConnectionMgrv2';
import { MetaTable } from '../utils/globals';
import { MetaService } from '../meta/meta.service';
import type {
LinkToAnotherRecordColumn,
Project,
} from '../models';
import type { LinkToAnotherRecordColumn, Project } from '../models';
import type SqlMgrv2 from '../db/sql-mgr/v2/SqlMgrv2';
import type {
ColumnReqType,
@ -124,6 +121,7 @@ export class ColumnsService {
UITypes.QrCode,
UITypes.Barcode,
UITypes.ForeignKey,
UITypes.Links,
].includes(column.uidt)
) {
if (column.uidt === colBody.uidt) {
@ -161,11 +159,19 @@ export class ColumnsService {
...column,
...colBody,
});
} else if (colBody.title !== column.title) {
} else {
if (colBody.title !== column.title) {
await Column.updateAlias(param.columnId, {
title: colBody.title,
});
}
if ('meta' in colBody && column.uidt === UITypes.Links) {
await Column.updateMeta({
colId: param.columnId,
meta: colBody.meta,
});
}
}
await this.updateRollupOrLookup(colBody, column);
} else {
NcError.notImplemented(
@ -1647,7 +1653,7 @@ export class ColumnsService {
(param.column as LinkToAnotherColumnReqType).title,
foreignKeyName,
(param.column as LinkToAnotherColumnReqType).virtual,
param.column['meta']
param.column['meta'],
);
} else if ((param.column as LinkToAnotherColumnReqType).type === 'mm') {
const aTn = `${param.project?.prefix ?? ''}_nc_m2m_${randomID()}`;
@ -1809,11 +1815,11 @@ export class ColumnsService {
await populateRollupForLTAR({
column: col1,
columnMeta: param.column['meta']
columnMeta: param.column['meta'],
});
await populateRollupForLTAR({
column: col2,
columnMeta: param.column['meta']
columnMeta: param.column['meta'],
});
// todo: create index for virtual relations as well

Loading…
Cancel
Save