From f2dc8e96b01226b72474aa3cca093586ed0f3b6a Mon Sep 17 00:00:00 2001 From: AlexHladin Date: Mon, 22 Jan 2024 18:16:25 +0200 Subject: [PATCH] refactor: Remove duplicated code in DB models --- .../src/db/sql-mgr/code/models/xc/BaseModelXcMeta.ts | 8 ++++++++ .../db/sql-mgr/code/models/xc/ModelXcMetaMssql.ts | 12 ++---------- .../db/sql-mgr/code/models/xc/ModelXcMetaMysql.ts | 12 ++---------- .../db/sql-mgr/code/models/xc/ModelXcMetaOracle.ts | 12 ++---------- .../src/db/sql-mgr/code/models/xc/ModelXcMetaPg.ts | 12 ++---------- .../sql-mgr/code/models/xc/ModelXcMetaSnowflake.ts | 12 ++---------- .../db/sql-mgr/code/models/xc/ModelXcMetaSqlite.ts | 12 ++---------- 7 files changed, 20 insertions(+), 60 deletions(-) diff --git a/packages/nocodb/src/db/sql-mgr/code/models/xc/BaseModelXcMeta.ts b/packages/nocodb/src/db/sql-mgr/code/models/xc/BaseModelXcMeta.ts index 1e3eee8f2d..224c37acc3 100644 --- a/packages/nocodb/src/db/sql-mgr/code/models/xc/BaseModelXcMeta.ts +++ b/packages/nocodb/src/db/sql-mgr/code/models/xc/BaseModelXcMeta.ts @@ -83,6 +83,14 @@ abstract class BaseModelXcMeta extends BaseRender { return columnsArr; } + protected renderXcHasMany(args) { + return JSON.stringify(args.hasMany); + } + + protected renderXcBelongsTo(args) { + return JSON.stringify(args.belongsTo); + } + public getObject() { return { tn: this.ctx.tn, diff --git a/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaMssql.ts b/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaMssql.ts index 8a1d85fca9..a9758f9a31 100644 --- a/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaMssql.ts +++ b/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaMssql.ts @@ -35,7 +35,7 @@ class ModelXcMetaMssql extends BaseModelXcMeta { /* for complex code provide a func and args - do derivation within the func cbk */ data.hasMany = { - func: this._renderXcHasMany.bind(this), + func: this.renderXcHasMany.bind(this), args: { tn: this.ctx.tn, columns: this.ctx.columns, @@ -45,7 +45,7 @@ class ModelXcMetaMssql extends BaseModelXcMeta { /* for complex code provide a func and args - do derivation within the func cbk */ data.belongsTo = { - func: this._renderXcBelongsTo.bind(this), + func: this.renderXcBelongsTo.bind(this), args: { tn: this.ctx.tn, columns: this.ctx.columns, @@ -56,14 +56,6 @@ class ModelXcMetaMssql extends BaseModelXcMeta { return data; } - _renderXcHasMany(args) { - return JSON.stringify(args.hasMany); - } - - _renderXcBelongsTo(args) { - return JSON.stringify(args.belongsTo); - } - /** * * @param args diff --git a/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaMysql.ts b/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaMysql.ts index faadaa9fd3..7ea3705955 100644 --- a/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaMysql.ts +++ b/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaMysql.ts @@ -35,7 +35,7 @@ class ModelXcMetaMysql extends BaseModelXcMeta { /* for complex code provide a func and args - do derivation within the func cbk */ data.hasMany = { - func: this._renderXcHasMany.bind(this), + func: this.renderXcHasMany.bind(this), args: { tn: this.ctx.tn, columns: this.ctx.columns, @@ -45,7 +45,7 @@ class ModelXcMetaMysql extends BaseModelXcMeta { /* for complex code provide a func and args - do derivation within the func cbk */ data.belongsTo = { - func: this._renderXcBelongsTo.bind(this), + func: this.renderXcBelongsTo.bind(this), args: { dbType: this.ctx.dbType, tn: this.ctx.tn, @@ -57,14 +57,6 @@ class ModelXcMetaMysql extends BaseModelXcMeta { return data; } - _renderXcHasMany(args) { - return JSON.stringify(args.hasMany); - } - - _renderXcBelongsTo(args) { - return JSON.stringify(args.belongsTo); - } - /** * * @param args diff --git a/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaOracle.ts b/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaOracle.ts index e216a151fe..6b5bf35eda 100644 --- a/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaOracle.ts +++ b/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaOracle.ts @@ -35,7 +35,7 @@ class ModelXcMetaOracle extends BaseModelXcMeta { /* for complex code provide a func and args - do derivation within the func cbk */ data.hasMany = { - func: this._renderXcHasMany.bind(this), + func: this.renderXcHasMany.bind(this), args: { tn: this.ctx.tn, columns: this.ctx.columns, @@ -45,7 +45,7 @@ class ModelXcMetaOracle extends BaseModelXcMeta { /* for complex code provide a func and args - do derivation within the func cbk */ data.belongsTo = { - func: this._renderXcBelongsTo.bind(this), + func: this.renderXcBelongsTo.bind(this), args: { dbType: this.ctx.dbType, tn: this.ctx.tn, @@ -57,14 +57,6 @@ class ModelXcMetaOracle extends BaseModelXcMeta { return data; } - _renderXcHasMany(args) { - return JSON.stringify(args.hasMany); - } - - _renderXcBelongsTo(args) { - return JSON.stringify(args.belongsTo); - } - /** * * @param args diff --git a/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaPg.ts b/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaPg.ts index edc8254221..8a14c520a6 100644 --- a/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaPg.ts +++ b/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaPg.ts @@ -35,7 +35,7 @@ class ModelXcMetaPg extends BaseModelXcMeta { /* for complex code provide a func and args - do derivation within the func cbk */ data.hasMany = { - func: this._renderXcHasMany.bind(this), + func: this.renderXcHasMany.bind(this), args: { tn: this.ctx.tn, columns: this.ctx.columns, @@ -45,7 +45,7 @@ class ModelXcMetaPg extends BaseModelXcMeta { /* for complex code provide a func and args - do derivation within the func cbk */ data.belongsTo = { - func: this._renderXcBelongsTo.bind(this), + func: this.renderXcBelongsTo.bind(this), args: { tn: this.ctx.tn, columns: this.ctx.columns, @@ -56,14 +56,6 @@ class ModelXcMetaPg extends BaseModelXcMeta { return data; } - _renderXcHasMany(args) { - return JSON.stringify(args.hasMany); - } - - _renderXcBelongsTo(args) { - return JSON.stringify(args.belongsTo); - } - /** * * @param args diff --git a/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaSnowflake.ts b/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaSnowflake.ts index bcfe3f7a49..0951ea3c0c 100644 --- a/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaSnowflake.ts +++ b/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaSnowflake.ts @@ -35,7 +35,7 @@ class ModelXcMetaSnowflake extends BaseModelXcMeta { /* for complex code provide a func and args - do derivation within the func cbk */ data.hasMany = { - func: this._renderXcHasMany.bind(this), + func: this.renderXcHasMany.bind(this), args: { tn: this.ctx.tn, columns: this.ctx.columns, @@ -45,7 +45,7 @@ class ModelXcMetaSnowflake extends BaseModelXcMeta { /* for complex code provide a func and args - do derivation within the func cbk */ data.belongsTo = { - func: this._renderXcBelongsTo.bind(this), + func: this.renderXcBelongsTo.bind(this), args: { tn: this.ctx.tn, columns: this.ctx.columns, @@ -56,14 +56,6 @@ class ModelXcMetaSnowflake extends BaseModelXcMeta { return data; } - _renderXcHasMany(args) { - return JSON.stringify(args.hasMany); - } - - _renderXcBelongsTo(args) { - return JSON.stringify(args.belongsTo); - } - /** * * @param args diff --git a/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaSqlite.ts b/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaSqlite.ts index f3ae40b1db..ec4f1fee93 100644 --- a/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaSqlite.ts +++ b/packages/nocodb/src/db/sql-mgr/code/models/xc/ModelXcMetaSqlite.ts @@ -35,7 +35,7 @@ class ModelXcMetaSqlite extends BaseModelXcMeta { /* for complex code provide a func and args - do derivation within the func cbk */ data.hasMany = { - func: this._renderXcHasMany.bind(this), + func: this.renderXcHasMany.bind(this), args: { tn: this.ctx.tn, columns: this.ctx.columns, @@ -45,7 +45,7 @@ class ModelXcMetaSqlite extends BaseModelXcMeta { /* for complex code provide a func and args - do derivation within the func cbk */ data.belongsTo = { - func: this._renderXcBelongsTo.bind(this), + func: this.renderXcBelongsTo.bind(this), args: { tn: this.ctx.tn, columns: this.ctx.columns, @@ -56,14 +56,6 @@ class ModelXcMetaSqlite extends BaseModelXcMeta { return data; } - _renderXcHasMany(args) { - return JSON.stringify(args.hasMany); - } - - _renderXcBelongsTo(args) { - return JSON.stringify(args.belongsTo); - } - /** * * @param args