Browse Source

add sort param in find-one

Signed-off-by: Vijay Kumar Rathore <professional.vijay8492@gmail.com>
pull/2465/head
Vijay Kumar Rathore 3 years ago committed by Pranav C
parent
commit
00c5f3a023
  1. 8
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts
  2. 2
      packages/nocodb/src/lib/meta/api/swagger/helpers/templates/paths.ts

8
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -119,12 +119,14 @@ class BaseModelSqlv2 {
args: {
where?: string;
filterArr?: Filter[];
sort?: string | string[];
} = {}
): Promise<any> {
const qb = this.dbDriver(this.model.table_name);
await this.selectObject({ qb });
const aliasColObjMap = await this.model.getAliasColObjMap();
const sorts = extractSortsObject(args?.sort, aliasColObjMap);
const filterObj = extractFilterFromXwhere(args?.where, aliasColObjMap);
await conditionV2(
@ -145,6 +147,12 @@ class BaseModelSqlv2 {
this.dbDriver
);
if (Array.isArray(sorts) && sorts?.length) {
await sortV2(sorts, qb, this.dbDriver);
} else if (this.model.primaryKey) {
qb.orderBy(this.model.primaryKey.column_name);
}
const data = await qb.first();
if (data) {

2
packages/nocodb/src/lib/meta/api/swagger/helpers/templates/paths.ts

@ -172,7 +172,7 @@ export const getModelPaths = async (ctx: {
operationId: 'db-table-row-find-one',
description: `Find first record matching the conditions.`,
tags: [ctx.tableName],
parameters: [fieldsParam, whereParam],
parameters: [fieldsParam, whereParam, sortParam],
responses: {
'200': {
description: 'OK',

Loading…
Cancel
Save