8000 feat: using field id as response by DarkPhoenix2704 · Pull Request #11721 · nocodb/nocodb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: using field id as response #11721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/nocodb/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ export const NC_EMAIL_ASSETS_BASE_URL = 'https://cdn.nocodb.com/emails/v2';

export const NC_RECURSIVE_MAX_DEPTH = 7;

export const QUERY_STRING_FIELD_ID_ON_RESULT = 'fieldIdOnResult';

export const S3_PATCH_KEYS = [
'uploads',
'thumbnails',
...(Object.values(PublicAttachmentScope) as string[]),
];

export const V3_INSERT_LIMIT = 10;
export const MAX_NESTING_DEPTH = 3;
export const MAX_CONCURRENT_TRANSFORMS = 50;
18 changes: 16 additions & 2 deletions packages/nocodb/src/db/BaseModelSqlv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ import {
} from '~/utils';
import { MetaTable } from '~/utils/globals';
import { chunkArray } from '~/utils/tsUtils';
import { QUERY_STRING_FIELD_ID_ON_RESULT } from '~/constants';

dayjs.extend(utc);

Expand Down Expand Up @@ -211,6 +212,9 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
extractOnlyPrimaries,
extractOrderColumn,
apiVersion,
skipSubstitutingColumnIds:
this.context.api_version === NcApiVersion.V3 &&
query?.[QUERY_STRING_FIELD_ID_ON_RESULT] === 'true',
});

await this.selectObject({
Expand All @@ -226,6 +230,9 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
data = await this.execAndParse(qb, null, {
first: true,
apiVersion,
skipSubstitutingColumnIds:
this.context.api_version === NcApiVersion.V3 &&
query?.[QUERY_STRING_FIELD_ID_ON_RESULT] === 'true',
});
} catch (e) {
if (
Expand Down Expand Up @@ -408,6 +415,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
validateFormula?: boolean;
throwErrorIfInvalidParams?: boolean;
limitOverride?: number;
skipSubstitutingColumnIds?: boolean;
} = {},
): Promise<any> {
const {
Expand Down Expand Up @@ -565,7 +573,8 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
let data;
try {
data = await this.execAndParse(qb, undefined, {
apiVersion: args.apiVersion,
apiVersion: args.apiVersion ?? this.context.api_version,
skipSubstitutingColumnIds: options.skipSubstitutingColumnIds,
});
} catch (e) {
if (validateFormula || !haveFormulaColumn(columns)) throw e;
Expand Down Expand Up @@ -2645,7 +2654,11 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
}
}

async chunkList(args: { pks: string[]; chunkSize?: number }) {
async chunkList(args: {
pks: string[];
chunkSize?: number;
apiVersion?: NcApiVersion;
}) {
const { pks, chunkSize = 1000 } = args;

const data = [];
Expand All @@ -2656,6 +2669,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
const chunkData = await this.list(
{
pks: chunk.join(','),
apiVersion: args.apiVersion,
},
{
limitOverride: chunk.length,
Expand Down
19 changes: 15 additions & 4 deletions packages/nocodb/src/helpers/dbHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,28 @@ export function _wherePk(
return where;
}

export function getCompositePkValue(primaryKeys: Column[], row) {
export function getCompositePkValue(
primaryKeys: Column[],
row,
option?: {
skipSubstitutingColumnIds?: boolean;
},
) {
if (row === null || row === undefined) {
NcError.requiredFieldMissing(primaryKeys.map((c) => c.title).join(','));
NcError.requiredFieldMissing(
primaryKeys
.map((c) => (option?.skipSubstitutingColumnIds ? c.id : c.title))
.join(','),
);
}

if (typeof row !== 'object') return row;

const pkIdOrTitleKey = option?.skipSubstitutingColumnIds ? 'id' : 'title';
if (primaryKeys.length > 1) {
return primaryKeys
.map((c) =>
(row[c.title] ?? row[c.column_name])
(row[c[pkIdOrTitleKey]] ?? row[c.column_name])
?.toString?.()
.replaceAll('_', '\\_'),
)
Expand All @@ -157,7 +168,7 @@ export function getCompositePkValue(primaryKeys: Column[], row) {

return (
primaryKeys[0] &&
(row[primaryKeys[0].title] ?? row[primaryKeys[0].column_name])
(row[primaryKeys[0][pkIdOrTitleKey]] ?? row[primaryKeys[0].column_name])
);
}

Expand Down
18 changes: 14 additions & 4 deletions packages/nocodb/src/helpers/getAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const getAst = async (
extractOrderColumn = false,
includeSortAndFilterColumns = false,
includeRowColorColumns = false,
skipSubstitutingColumnIds = false,
}: {
query?: RequestQuery;
extractOnlyPrimaries?: boolean;
Expand All @@ -73,6 +74,7 @@ const getAst = async (
extractOrderColumn?: boolean;
includeSortAndFilterColumns?: boolean;
includeRowColorColumns?: boolean;
skipSubstitutingColumnIds?: boolean;
},
): Promise<{
ast: Ast;
Expand All @@ -83,6 +85,10 @@ const getAst = async (
dependencyFields.nested = dependencyFields.nested || {};
dependencyFields.fieldsSet = dependencyFields.fieldsSet || new Set();

const getFieldKey = (col: Column) => {
return skipSubstitutingColumnIds ? col.id : col.title;
};

let coverImageId;
let dependencyFieldsForCalenderView;
let kanbanGroupColumnId;
Expand Down Expand Up @@ -131,9 +137,12 @@ const getAst = async (
if (extractOnlyPrimaries) {
const ast: Ast = {
...(model.primaryKeys
? model.primaryKeys.reduce((o, pk) => ({ ...o, [pk.title]: 1 }), {})
? model.primaryKeys.reduce(
(o, pk) => ({ ...o, [getFieldKey(pk)]: 1 }),
{},
)
: {}),
...(model.displayValue ? { [model.displayValue.title]: 1 } : {}),
...(model.displayValue ? { [getFieldKey(model.displayValue)]: 1 } : {}),
};
await Promise.all(
model.primaryKeys.map((c) =>
Expand All @@ -150,7 +159,7 @@ const getAst = async (
const ast: Ast = {
...(dependencyFieldsForCalenderView || []).reduce((o, f) => {
const col = model.columns.find((c) => c.id === f);
return { ...o, [col.title]: 1 };
return { ...o, [getFieldKey(col)]: 1 };
}, {}),
};

Expand Down Expand Up @@ -215,6 +224,7 @@ const getAst = async (

const ast: Ast = await columns.reduce(async (obj, col: Column) => {
let value: number | boolean | { [key: string]: any } = 1;
// TODO: also get from col.id
const nestedFields =
query?.nested?.[col.title]?.fields || query?.nested?.[col.title]?.f;
if (nestedFields && nestedFields !== '*') {
Expand Down Expand Up @@ -333,7 +343,7 @@ const getAst = async (

return {
...(await obj),
[col.title]: isRequested,
[getFieldKey(col)]: isRequested,
};
}, Promise.resolve({}));

Expand Down
6 changes: 5 additions & 1 deletion packages/nocodb/src/services/datas.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable, Logger } from '@nestjs/common';
import { isLinksOrLTAR, NcSDKErrorV2 } from 'nocodb-sdk';
import type { NcApiVersion } from 'nocodb-sdk';
import { NcApiVersion } from 'nocodb-sdk';
import type { BaseModelSqlv2 } from '~/db/BaseModelSqlv2';
import type { PathParams } from '~/helpers/dataHelpers';
import type { NcContext } from '~/interface/config';
Expand All @@ -13,6 +13,7 @@ import { PagedResponseImpl } from '~/helpers/PagedResponse';
import { Base, Column, Model, Source, View } from '~/models';
import { nocoExecute } from '~/utils';
import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2';
import { QUERY_STRING_FIELD_ID_ON_RESULT } from '~/constants';

@Injectable()
export class DatasService {
Expand Down Expand Up @@ -281,6 +282,9 @@ export class DatasService {
throwErrorIfInvalidParams: param.throwErrorIfInvalidParams,
ignorePagination: param.ignorePagination,
limitOverride: param.limitOverride,
skipSubstitutingColumnIds:
context.api_version === NcApiVersion.V3 &&
query?.[QUERY_STRING_FIELD_ID_ON_RESULT] === 'true',
},
),
{},
Expand Down
Loading
Loading
0