Browse Source

Merge pull request #7529 from AlexHladin/refactor/remove-duplicated-code-for-models

refactor: Remove duplicated code in models
pull/7543/head
աӄա 9 months ago committed by GitHub
parent
commit
5ab5b4d3d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 51
      packages/nocodb/src/db/sql-mgr/code/models/xc/BaseModelXcMeta.ts
  2. 49
      packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaMssql.ts
  3. 48
      packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaMysql.ts
  4. 48
      packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaOracle.ts
  5. 48
      packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaPg.ts
  6. 48
      packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaSnowflake.ts
  7. 48
      packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaSqlite.ts
  8. 2
      packages/nocodb/src/version-upgrader/v1-legacy/BaseApiBuilder.ts

51
packages/nocodb/src/db/sql-mgr/code/models/xc/BaseModelXcMeta.ts

@ -101,12 +101,11 @@ abstract class BaseModelXcMeta extends BaseRender {
belongsTo: this.ctx.belongsTo,
db_type: this.ctx.db_type,
type: this.ctx.type,
v: this.getVitualColumns(),
v: this.getVirtualColumns(),
};
}
public getVitualColumns(): any[] {
public getVirtualColumns(): any[] {
// todo: handle duplicate relation
const virtualColumns = [
...(this.ctx.hasMany || []).map((hm) => {
@ -138,6 +137,52 @@ abstract class BaseModelXcMeta extends BaseRender {
public mapDefaultDisplayValue(columnsArr: any[]): void {
mapDefaultDisplayValue(columnsArr);
}
/**
*
* @param args
* @param args.columns
* @param args.relations
* @returns {string}
* @private
*/
protected renderXcColumns(args) {
let str = '[\r\n';
for (let i = 0; i < args.columns.length; ++i) {
str += `{\r\n`;
str += `cn: '${args.columns[i].cn}',\r\n`;
str += `type: '${this._getAbstractType(args.columns[i])}',\r\n`;
str += `dt: '${args.columns[i].dt}',\r\n`;
if (args.columns[i].rqd) str += `rqd: ${args.columns[i].rqd},\r\n`;
if (args.columns[i].cdf) {
str += `default: "${args.columns[i].cdf}",\r\n`;
str += `columnDefault: "${args.columns[i].cdf}",\r\n`;
}
if (args.columns[i].un) str += `un: ${args.columns[i].un},\r\n`;
if (args.columns[i].pk) str += `pk: ${args.columns[i].pk},\r\n`;
if (args.columns[i].ai) str += `ai: ${args.columns[i].ai},\r\n`;
if (args.columns[i].dtxp) str += `dtxp: "${args.columns[i].dtxp}",\r\n`;
if (args.columns[i].dtxs) str += `dtxs: ${args.columns[i].dtxs},\r\n`;
str += `validate: {
func: [],
args: [],
msg: []
},`;
str += `},\r\n`;
}
str += ']\r\n';
return str;
}
}
export default BaseModelXcMeta;

49
packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaMssql.ts

@ -25,7 +25,7 @@ class ModelXcMetaMssql extends BaseModelXcMeta {
/* for complex code provide a func and args - do derivation within the func cbk */
data.columns = {
func: this._renderXcColumns.bind(this),
func: this.renderXcColumns.bind(this),
args: {
tn: this.ctx.tn,
columns: this.ctx.columns,
@ -56,53 +56,6 @@ class ModelXcMetaMssql extends BaseModelXcMeta {
return data;
}
/**
*
* @param args
* @param args.columns
* @param args.relations
* @returns {string}
* @private
*/
_renderXcColumns(args) {
let str = '[\r\n';
for (let i = 0; i < args.columns.length; ++i) {
str += `{\r\n`;
str += `cn: '${args.columns[i].cn}',\r\n`;
str += `type: '${this._getAbstractType(args.columns[i])}',\r\n`;
str += `dt: '${args.columns[i].dt}',\r\n`;
if (args.columns[i].rqd) str += `rqd: ${args.columns[i].rqd},\r\n`;
if (args.columns[i].cdf) {
str += `default: "${args.columns[i].cdf}",\r\n`;
str += `columnDefault: "${args.columns[i].cdf}",\r\n`;
}
if (args.columns[i].un) str += `un: ${args.columns[i].un},\r\n`;
if (args.columns[i].pk) str += `pk: ${args.columns[i].pk},\r\n`;
if (args.columns[i].ai) str += `ai: ${args.columns[i].ai},\r\n`;
if (args.columns[i].dtxp) str += `dtxp: "${args.columns[i].dtxp}",\r\n`;
if (args.columns[i].dtxs) str += `dtxs: ${args.columns[i].dtxs},\r\n`;
str += `validate: {
func: [],
args: [],
msg: []
},`;
str += `},\r\n`;
}
str += ']\r\n';
return str;
}
_getAbstractType(column) {
let str = '';
switch (column.dt) {

48
packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaMysql.ts

@ -25,7 +25,7 @@ class ModelXcMetaMysql extends BaseModelXcMeta {
/* for complex code provide a func and args - do derivation within the func cbk */
data.columns = {
func: this._renderXcColumns.bind(this),
func: this.renderXcColumns.bind(this),
args: {
tn: this.ctx.tn,
columns: this.ctx.columns,
@ -57,52 +57,6 @@ class ModelXcMetaMysql extends BaseModelXcMeta {
return data;
}
/**
*
* @param args
* @param args.columns
* @param args.relations
* @returns {string}
* @private
*/
_renderXcColumns(args) {
let str = '[\r\n';
for (let i = 0; i < args.columns.length; ++i) {
str += `{\r\n`;
str += `cn: '${args.columns[i].cn}',\r\n`;
str += `type: '${this._getAbstractType(args.columns[i])}',\r\n`;
str += `dt: '${args.columns[i].dt}',\r\n`;
if (args.columns[i].rqd) str += `rqd: ${args.columns[i].rqd},\r\n`;
if (args.columns[i].cdf) {
str += `default: "${args.columns[i].cdf}",\r\n`;
str += `columnDefault: "${args.columns[i].cdf}",\r\n`;
}
if (args.columns[i].un) str += `un: ${args.columns[i].un},\r\n`;
if (args.columns[i].pk) str += `pk: ${args.columns[i].pk},\r\n`;
if (args.columns[i].ai) str += `ai: ${args.columns[i].ai},\r\n`;
if (args.columns[i].dtxp) str += `dtxp: "${args.columns[i].dtxp}",\r\n`;
if (args.columns[i].dtxs) str += `dtxs: ${args.columns[i].dtxs},\r\n`;
str += `validate: {
func: [],
args: [],
msg: []
},`;
str += `},\r\n`;
}
str += ']\r\n';
return str;
}
/* getXcColumnsObject(args) {
const columnsArr = [];

48
packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaOracle.ts

@ -25,7 +25,7 @@ class ModelXcMetaOracle extends BaseModelXcMeta {
/* for complex code provide a func and args - do derivation within the func cbk */
data.columns = {
func: this._renderXcColumns.bind(this),
func: this.renderXcColumns.bind(this),
args: {
tn: this.ctx.tn,
columns: this.ctx.columns,
@ -57,52 +57,6 @@ class ModelXcMetaOracle extends BaseModelXcMeta {
return data;
}
/**
*
* @param args
* @param args.columns
* @param args.relations
* @returns {string}
* @private
*/
_renderXcColumns(args) {
let str = '[\r\n';
for (let i = 0; i < args.columns.length; ++i) {
str += `{\r\n`;
str += `cn: '${args.columns[i].cn}',\r\n`;
str += `type: '${this._getAbstractType(args.columns[i])}',\r\n`;
str += `dt: '${args.columns[i].dt}',\r\n`;
if (args.columns[i].rqd) str += `rqd: ${args.columns[i].rqd},\r\n`;
if (args.columns[i].cdf) {
str += `default: "${args.columns[i].cdf}",\r\n`;
str += `columnDefault: "${args.columns[i].cdf}",\r\n`;
}
if (args.columns[i].un) str += `un: ${args.columns[i].un},\r\n`;
if (args.columns[i].pk) str += `pk: ${args.columns[i].pk},\r\n`;
if (args.columns[i].ai) str += `ai: ${args.columns[i].ai},\r\n`;
if (args.columns[i].dtxp) str += `dtxp: "${args.columns[i].dtxp}",\r\n`;
if (args.columns[i].dtxs) str += `dtxs: ${args.columns[i].dtxs},\r\n`;
str += `validate: {
func: [],
args: [],
msg: []
},`;
str += `},\r\n`;
}
str += ']\r\n';
return str;
}
/* getXcColumnsObject(args) {
const columnsArr = [];

48
packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaPg.ts

@ -25,7 +25,7 @@ class ModelXcMetaPg extends BaseModelXcMeta {
/* for complex code provide a func and args - do derivation within the func cbk */
data.columns = {
func: this._renderXcColumns.bind(this),
func: this.renderXcColumns.bind(this),
args: {
tn: this.ctx.tn,
columns: this.ctx.columns,
@ -56,52 +56,6 @@ class ModelXcMetaPg extends BaseModelXcMeta {
return data;
}
/**
*
* @param args
* @param args.columns
* @param args.relations
* @returns {string}
* @private
*/
_renderXcColumns(args) {
let str = '[\r\n';
for (let i = 0; i < args.columns.length; ++i) {
str += `{\r\n`;
str += `cn: '${args.columns[i].cn}',\r\n`;
str += `type: '${this._getAbstractType(args.columns[i])}',\r\n`;
str += `dt: '${args.columns[i].dt}',\r\n`;
if (args.columns[i].rqd) str += `rqd: ${args.columns[i].rqd},\r\n`;
if (args.columns[i].cdf) {
str += `default: "${args.columns[i].cdf}",\r\n`;
str += `columnDefault: "${args.columns[i].cdf}",\r\n`;
}
if (args.columns[i].un) str += `un: ${args.columns[i].un},\r\n`;
if (args.columns[i].pk) str += `pk: ${args.columns[i].pk},\r\n`;
if (args.columns[i].ai) str += `ai: ${args.columns[i].ai},\r\n`;
if (args.columns[i].dtxp) str += `dtxp: "${args.columns[i].dtxp}",\r\n`;
if (args.columns[i].dtxs) str += `dtxs: ${args.columns[i].dtxs},\r\n`;
str += `validate: {
func: [],
args: [],
msg: []
},`;
str += `},\r\n`;
}
str += ']\r\n';
return str;
}
_getAbstractType(column) {
let str = '';
switch (column.dt) {

48
packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaSnowflake.ts

@ -25,7 +25,7 @@ class ModelXcMetaSnowflake extends BaseModelXcMeta {
/* for complex code provide a func and args - do derivation within the func cbk */
data.columns = {
func: this._renderXcColumns.bind(this),
func: this.renderXcColumns.bind(this),
args: {
tn: this.ctx.tn,
columns: this.ctx.columns,
@ -56,52 +56,6 @@ class ModelXcMetaSnowflake extends BaseModelXcMeta {
return data;
}
/**
*
* @param args
* @param args.columns
* @param args.relations
* @returns {string}
* @private
*/
_renderXcColumns(args) {
let str = '[\r\n';
for (let i = 0; i < args.columns.length; ++i) {
str += `{\r\n`;
str += `cn: '${args.columns[i].cn}',\r\n`;
str += `type: '${this._getAbstractType(args.columns[i])}',\r\n`;
str += `dt: '${args.columns[i].dt}',\r\n`;
if (args.columns[i].rqd) str += `rqd: ${args.columns[i].rqd},\r\n`;
if (args.columns[i].cdf) {
str += `default: "${args.columns[i].cdf}",\r\n`;
str += `columnDefault: "${args.columns[i].cdf}",\r\n`;
}
if (args.columns[i].un) str += `un: ${args.columns[i].un},\r\n`;
if (args.columns[i].pk) str += `pk: ${args.columns[i].pk},\r\n`;
if (args.columns[i].ai) str += `ai: ${args.columns[i].ai},\r\n`;
if (args.columns[i].dtxp) str += `dtxp: "${args.columns[i].dtxp}",\r\n`;
if (args.columns[i].dtxs) str += `dtxs: ${args.columns[i].dtxs},\r\n`;
str += `validate: {
func: [],
args: [],
msg: []
},`;
str += `},\r\n`;
}
str += ']\r\n';
return str;
}
_getAbstractType(column) {
let str = '';
switch (column.dt) {

48
packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaSqlite.ts

@ -25,7 +25,7 @@ class ModelXcMetaSqlite extends BaseModelXcMeta {
/* for complex code provide a func and args - do derivation within the func cbk */
data.columns = {
func: this._renderXcColumns.bind(this),
func: this.renderXcColumns.bind(this),
args: {
tn: this.ctx.tn,
columns: this.ctx.columns,
@ -56,52 +56,6 @@ class ModelXcMetaSqlite extends BaseModelXcMeta {
return data;
}
/**
*
* @param args
* @param args.columns
* @param args.relations
* @returns {string}
* @private
*/
_renderXcColumns(args) {
let str = '[\r\n';
for (let i = 0; i < args.columns.length; ++i) {
str += `{\r\n`;
str += `cn: '${args.columns[i].cn}',\r\n`;
str += `type: '${this._getAbstractType(args.columns[i])}',\r\n`;
str += `dt: '${args.columns[i].dt}',\r\n`;
if (args.columns[i].rqd) str += `rqd: ${args.columns[i].rqd},\r\n`;
if (args.columns[i].cdf) {
str += `default: "${args.columns[i].cdf}",\r\n`;
str += `columnDefault: "${args.columns[i].cdf}",\r\n`;
}
if (args.columns[i].un) str += `un: ${args.columns[i].un},\r\n`;
if (args.columns[i].pk) str += `pk: ${args.columns[i].pk},\r\n`;
if (args.columns[i].ai) str += `ai: ${args.columns[i].ai},\r\n`;
if (args.columns[i].dtxp) str += `dtxp: "${args.columns[i].dtxp}",\r\n`;
if (args.columns[i].dtxs) str += `dtxs: ${args.columns[i].dtxs},\r\n`;
str += `validate: {
func: [],
args: [],
msg: []
},`;
str += `},\r\n`;
}
str += ']\r\n';
return str;
}
protected _getAbstractType(column) {
let str = '';
switch (column.dt) {

2
packages/nocodb/src/version-upgrader/v1-legacy/BaseApiBuilder.ts

@ -373,7 +373,7 @@ export default abstract class BaseApiBuilder<T extends Noco> {
dir: '',
ctx,
filename: '',
}).getVitualColumns();
}).getVirtualColumns();
// set default display values
ModelXcMetaFactory.create(
this.connectionConfig,

Loading…
Cancel
Save