Browse Source

refactor(nocodb): rename extractRawQueryAndExec to execAndParse

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

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

@ -100,7 +100,7 @@ class BaseModelSqlv2 {
qb.where(_wherePk(this.model.primaryKeys, id)); qb.where(_wherePk(this.model.primaryKeys, id));
let data = (await this.extractRawQueryAndExec(qb))?.[0]; let data = (await this.execAndParse(qb))?.[0];
if (data) { if (data) {
const proto = await this.getProto(); const proto = await this.getProto();
@ -252,7 +252,7 @@ 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.execAndParse(qb);
return data?.map((d) => { return data?.map((d) => {
d.__proto__ = proto; d.__proto__ = proto;
@ -423,7 +423,7 @@ class BaseModelSqlv2 {
.as('list') .as('list')
); );
let children = await this.extractRawQueryAndExec(childQb, childTable); let children = await this.execAndParse(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, childTable); let children = await this.execAndParse(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, childTable); let children = await this.execAndParse(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, childTable); let children = await this.execAndParse(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, childTable); let data = await this.execAndParse(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, childTable); let data = await this.execAndParse(qb, childTable);
return data.map((c) => { return data.map((c) => {
c.__proto__ = proto; c.__proto__ = proto;
@ -1525,7 +1525,7 @@ class BaseModelSqlv2 {
query.returning( query.returning(
`${this.model.primaryKey.column_name} as ${this.model.primaryKey.title}` `${this.model.primaryKey.column_name} as ${this.model.primaryKey.title}`
); );
response = await this.extractRawQueryAndExec(query); response = await this.execAndParse(query);
} }
const ai = this.model.columns.find((c) => c.ai); const ai = this.model.columns.find((c) => c.ai);
@ -1535,7 +1535,7 @@ class BaseModelSqlv2 {
// handle if autogenerated primary key is used // handle if autogenerated primary key is used
if (ag) { if (ag) {
if (!response) await this.extractRawQueryAndExec(query); if (!response) await this.execAndParse(query);
response = await this.readByPk(data[ag.title]); response = await this.readByPk(data[ag.title]);
} else if ( } else if (
!response || !response ||
@ -1545,7 +1545,7 @@ class BaseModelSqlv2 {
if (response?.length) { if (response?.length) {
id = response[0]; id = response[0];
} else { } else {
const res = await this.extractRawQueryAndExec(query); const res = await this.execAndParse(query);
id = res?.id ?? res[0]?.insertId; id = res?.id ?? res[0]?.insertId;
} }
@ -1650,7 +1650,7 @@ class BaseModelSqlv2 {
.update(updateObj) .update(updateObj)
.where(await this._wherePk(id)); .where(await this._wherePk(id));
await this.extractRawQueryAndExec(query); await this.execAndParse(query);
const response = await this.readByPk(id); const response = await this.readByPk(id);
await this.afterUpdate(response, trx, cookie); await this.afterUpdate(response, trx, cookie);
@ -2755,7 +2755,7 @@ class BaseModelSqlv2 {
return await qb; return await qb;
} }
private async extractRawQueryAndExec( private async execAndParse(
qb: Knex.QueryBuilder, qb: Knex.QueryBuilder,
childTable?: Model childTable?: Model
) { ) {

Loading…
Cancel
Save