Browse Source

feat: add exist logic to BaseModelSqlv2

pull/2070/head
Wing-Kam Wong 3 years ago
parent
commit
8f74ecd14a
  1. 32
      packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSqlv2.ts

32
packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSqlv2.ts

@ -89,6 +89,38 @@ class BaseModelSqlv2 {
return data; return data;
} }
public async exist(
args: {
where?: string;
filterArr?: Filter[];
} = {}
): Promise<any> {
const qb = this.dbDriver(this.model.table_name);
await this.selectObject({ qb });
const aliasColObjMap = await this.model.getAliasColObjMap();
const filterObj = extractFilterFromXwhere(args?.where, aliasColObjMap);
await conditionV2(
[
new Filter({
children: args.filterArr || [],
is_group: true,
logical_op: 'and'
}),
new Filter({
children: filterObj,
is_group: true,
logical_op: 'and'
}),
...(args.filterArr || [])
],
qb,
this.dbDriver
);
return !!(await qb.first());
}
public async findOne( public async findOne(
args: { args: {
where?: string; where?: string;

Loading…
Cancel
Save