Browse Source

refactor(nocodb): move convertAttachmentType to extractRawQueryAndExec

pull/4612/head
Wing-Kam Wong 2 years ago
parent
commit
fa8ac94d56
  1. 41
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

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

@ -103,7 +103,6 @@ class BaseModelSqlv2 {
let data = (await this.extractRawQueryAndExec(qb))?.[0]; let data = (await this.extractRawQueryAndExec(qb))?.[0];
if (data) { if (data) {
data = this.convertAttachmentType(data);
const proto = await this.getProto(); const proto = await this.getProto();
data.__proto__ = proto; data.__proto__ = proto;
} }
@ -162,7 +161,6 @@ class BaseModelSqlv2 {
let data = await qb.first(); let data = await qb.first();
if (data) { if (data) {
data = this.convertAttachmentType(data);
const proto = await this.getProto(); const proto = await this.getProto();
data.__proto__ = proto; data.__proto__ = proto;
} }
@ -255,7 +253,6 @@ class BaseModelSqlv2 {
if (!ignoreViewFilterAndSort) applyPaginate(qb, rest); if (!ignoreViewFilterAndSort) applyPaginate(qb, rest);
const proto = await this.getProto(); const proto = await this.getProto();
let data = await this.extractRawQueryAndExec(qb); let data = await this.extractRawQueryAndExec(qb);
data = this.convertAttachmentType(data);
return data?.map((d) => { return data?.map((d) => {
d.__proto__ = proto; d.__proto__ = proto;
@ -367,7 +364,7 @@ class BaseModelSqlv2 {
qb.groupBy(args.column_name); qb.groupBy(args.column_name);
if (sorts) await sortV2(sorts, qb, this.dbDriver); if (sorts) await sortV2(sorts, qb, this.dbDriver);
applyPaginate(qb, rest); applyPaginate(qb, rest);
return this.convertAttachmentType(await qb); return await qb;
} }
async multipleHmList({ colId, ids }, args: { limit?; offset? } = {}) { async multipleHmList({ colId, ids }, args: { limit?; offset? } = {}) {
@ -427,7 +424,6 @@ class BaseModelSqlv2 {
); );
let children = await this.extractRawQueryAndExec(childQb); let children = await this.extractRawQueryAndExec(childQb);
children = this.convertAttachmentType(children);
const proto = await ( const proto = await (
await Model.getBaseModelSQL({ await Model.getBaseModelSQL({
id: childTable.id, id: childTable.id,
@ -555,7 +551,6 @@ class BaseModelSqlv2 {
await childModel.selectObject({ qb }); await childModel.selectObject({ qb });
let children = await this.extractRawQueryAndExec(qb); let children = await this.extractRawQueryAndExec(qb);
children = this.convertAttachmentType(children);
const proto = await ( const proto = await (
await Model.getBaseModelSQL({ await Model.getBaseModelSQL({
@ -676,7 +671,6 @@ class BaseModelSqlv2 {
if (this.isMySQL) { if (this.isMySQL) {
children = children[0]; children = children[0];
} }
children = this.convertAttachmentType(children);
const proto = await ( const proto = await (
await Model.getBaseModelSQL({ await Model.getBaseModelSQL({
id: rtnId, id: rtnId,
@ -742,7 +736,6 @@ class BaseModelSqlv2 {
qb.offset(+rest?.offset || 0); qb.offset(+rest?.offset || 0);
let children = await this.extractRawQueryAndExec(qb); let children = await this.extractRawQueryAndExec(qb);
children = this.convertAttachmentType(children);
const proto = await ( const proto = await (
await Model.getBaseModelSQL({ id: rtnId, dbDriver: this.dbDriver }) await Model.getBaseModelSQL({ id: rtnId, dbDriver: this.dbDriver })
).getProto(); ).getProto();
@ -969,7 +962,6 @@ class BaseModelSqlv2 {
const proto = await childModel.getProto(); const proto = await childModel.getProto();
let data = await qb; let data = await qb;
data = this.convertAttachmentType(data);
return data.map((c) => { return data.map((c) => {
c.__proto__ = proto; c.__proto__ = proto;
return c; return c;
@ -1084,7 +1076,6 @@ class BaseModelSqlv2 {
const proto = await childModel.getProto(); const proto = await childModel.getProto();
let data = await this.extractRawQueryAndExec(qb); let data = await this.extractRawQueryAndExec(qb);
data = this.convertAttachmentType(data);
return data.map((c) => { return data.map((c) => {
c.__proto__ = proto; c.__proto__ = proto;
@ -1203,7 +1194,6 @@ class BaseModelSqlv2 {
const proto = await parentModel.getProto(); const proto = await parentModel.getProto();
let data = await this.extractRawQueryAndExec(qb); let data = await this.extractRawQueryAndExec(qb);
data = this.convertAttachmentType(data);
return data.map((c) => { return data.map((c) => {
c.__proto__ = proto; c.__proto__ = proto;
@ -2663,7 +2653,6 @@ class BaseModelSqlv2 {
const proto = await this.getProto(); const proto = await this.getProto();
let data = await groupedQb; let data = await groupedQb;
data = this.convertAttachmentType(data);
const result = data?.map((d) => { const result = data?.map((d) => {
d.__proto__ = proto; d.__proto__ = proto;
return d; return d;
@ -2773,21 +2762,25 @@ class BaseModelSqlv2 {
} else { } else {
query = sanitize(query); query = sanitize(query);
} }
return this.isPg return this.convertAttachmentType(
? (await this.dbDriver.raw(query))?.rows this.isPg
: query.slice(0, 6) === 'select' && !this.isMssql ? (await this.dbDriver.raw(query))?.rows
? await this.dbDriver.from( : query.slice(0, 6) === 'select' && !this.isMssql
this.dbDriver.raw(query).wrap('(', ') __nc_alias') ? await this.dbDriver.from(
) this.dbDriver.raw(query).wrap('(', ') __nc_alias')
: await this.dbDriver.raw(query); )
: await this.dbDriver.raw(query)
);
} }
private _convertAttachmentType(attachmentColumns, d) { private _convertAttachmentType(attachmentColumns, d) {
attachmentColumns.forEach((col) => { if (d) {
if (d[col.title] && typeof d[col.title] === 'string') { attachmentColumns.forEach((col) => {
d[col.title] = JSON.parse(d[col.title]); if (d[col.title] && typeof d[col.title] === 'string') {
} d[col.title] = JSON.parse(d[col.title]);
}); }
});
}
return d; return d;
} }

Loading…
Cancel
Save