Browse Source

fix(nocodb): add try catch and handle LTAR case

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

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

@ -423,7 +423,7 @@ class BaseModelSqlv2 {
.as('list') .as('list')
); );
let children = await this.extractRawQueryAndExec(childQb); let children = await this.extractRawQueryAndExec(childQb, childTable);
const proto = await ( const proto = await (
await Model.getBaseModelSQL({ await Model.getBaseModelSQL({
id: childTable.id, id: childTable.id,
@ -550,7 +550,7 @@ class BaseModelSqlv2 {
await childModel.selectObject({ qb }); await childModel.selectObject({ qb });
let children = await this.extractRawQueryAndExec(qb); let children = await this.extractRawQueryAndExec(qb, childTable);
const proto = await ( const proto = await (
await Model.getBaseModelSQL({ await Model.getBaseModelSQL({
@ -667,7 +667,7 @@ class BaseModelSqlv2 {
!this.isSqlite !this.isSqlite
); );
let children = await this.extractRawQueryAndExec(finalQb); let children = await this.extractRawQueryAndExec(finalQb, childTable);
if (this.isMySQL) { if (this.isMySQL) {
children = children[0]; children = children[0];
} }
@ -735,7 +735,7 @@ class BaseModelSqlv2 {
qb.limit(+rest?.limit || 25); qb.limit(+rest?.limit || 25);
qb.offset(+rest?.offset || 0); qb.offset(+rest?.offset || 0);
let children = await this.extractRawQueryAndExec(qb); let children = await this.extractRawQueryAndExec(qb, childTable);
const proto = await ( const proto = await (
await Model.getBaseModelSQL({ id: rtnId, dbDriver: this.dbDriver }) await Model.getBaseModelSQL({ id: rtnId, dbDriver: this.dbDriver })
).getProto(); ).getProto();
@ -1075,7 +1075,7 @@ class BaseModelSqlv2 {
applyPaginate(qb, rest); applyPaginate(qb, rest);
const proto = await childModel.getProto(); const proto = await childModel.getProto();
let data = await this.extractRawQueryAndExec(qb); let data = await this.extractRawQueryAndExec(qb, childTable);
return data.map((c) => { return data.map((c) => {
c.__proto__ = proto; c.__proto__ = proto;
@ -1193,7 +1193,7 @@ class BaseModelSqlv2 {
applyPaginate(qb, rest); applyPaginate(qb, rest);
const proto = await parentModel.getProto(); const proto = await parentModel.getProto();
let data = await this.extractRawQueryAndExec(qb); let data = await this.extractRawQueryAndExec(qb, childTable);
return data.map((c) => { return data.map((c) => {
c.__proto__ = proto; c.__proto__ = proto;
@ -2755,7 +2755,10 @@ class BaseModelSqlv2 {
return await qb; return await qb;
} }
private async extractRawQueryAndExec(qb: Knex.QueryBuilder) { private async extractRawQueryAndExec(
qb: Knex.QueryBuilder,
childTable?: Model
) {
let query = qb.toQuery(); let query = qb.toQuery();
if (!this.isPg && !this.isMssql) { if (!this.isPg && !this.isMssql) {
query = unsanitize(qb.toQuery()); query = unsanitize(qb.toQuery());
@ -2769,28 +2772,34 @@ class BaseModelSqlv2 {
? await this.dbDriver.from( ? await this.dbDriver.from(
this.dbDriver.raw(query).wrap('(', ') __nc_alias') this.dbDriver.raw(query).wrap('(', ') __nc_alias')
) )
: await this.dbDriver.raw(query) : await this.dbDriver.raw(query),
childTable
); );
} }
private _convertAttachmentType(attachmentColumns, d) { private _convertAttachmentType(
if (d) { attachmentColumns: Record<string, any>[],
attachmentColumns.forEach((col) => { d: Record<string, any>
if (d[col.title] && typeof d[col.title] === 'string') { ) {
d[col.title] = JSON.parse(d[col.title]); try {
} if (d) {
}); attachmentColumns.forEach((col) => {
} if (d[col.title] && typeof d[col.title] === 'string') {
d[col.title] = JSON.parse(d[col.title]);
}
});
}
} catch {}
return d; return d;
} }
private convertAttachmentType(data) { private convertAttachmentType(data: Record<string, any>, childTable?: Model) {
// attachment is stored in text and parse in UI // attachment is stored in text and parse in UI
// convertAttachmentType is used to convert the response in string to array of object in API response // convertAttachmentType is used to convert the response in string to array of object in API response
if (data) { if (data) {
const attachmentColumns = this.model.columns.filter( const attachmentColumns = (
(c) => c.uidt === UITypes.Attachment childTable ? childTable.columns : this.model.columns
); ).filter((c) => c.uidt === UITypes.Attachment);
if (attachmentColumns.length) { if (attachmentColumns.length) {
if (Array.isArray(data)) { if (Array.isArray(data)) {
data = data.map((d) => data = data.map((d) =>

Loading…
Cancel
Save