Browse Source

refactor: revise based on PR comment

pull/2424/head
Wing-Kam Wong 3 years ago
parent
commit
271fe9ba13
  1. 4
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts
  2. 7
      packages/nocodb/src/lib/models/Model.ts

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

@ -314,9 +314,7 @@ class BaseModelSqlv2 {
qb.count(this.model.primaryKey?.column_name || '*', {
as: 'count'
}).first();
const res = (await this.dbDriver.raw(
qb.toQuery().replaceAll('\\?', '?')
)) as any;
const res = (await this.dbDriver.raw(unsanitize(qb.toQuery()))) as any;
return (this.isPg ? res.rows[0] : res[0][0] ?? res[0]).count;
}

7
packages/nocodb/src/lib/models/Model.ts

@ -20,6 +20,7 @@ import {
import View from './View';
import { NcError } from '../meta/helpers/catchError';
import Audit from './Audit';
import { sanitize } from '../db/sql-data-mapper/lib/sql/helpers/sanitize';
export default class Model implements TableType {
copy_enabled: boolean;
@ -405,11 +406,7 @@ export default class Model implements TableType {
if (isVirtualCol(col)) continue;
const val = data?.[col.column_name] ?? data?.[col.title];
if (val !== undefined) {
insertObj[
col.column_name.replace(/([^\\]|^)(\?+)/g, (_, m1, m2) => {
return `${m1}${m2.split('?').join('\\?')}`;
})
] = val;
insertObj[sanitize(col.column_name)] = val;
}
}
return insertObj;

Loading…
Cancel
Save