从表动态传递名称到函数定义

问题描述

在我的MysqL数据库中,有几个具有相同名称的表。 table_1,table_2,table_3,...,table_n

所有这些表都具有完全相同的结构,我想将这个参数传递给sequelize的define函数使其动态,有没有办法做到这一点?

const { Sequelize,DataTypes } = require("sequelize");
const connection = require("./database");

const Table = connection.define('table_1',{
    name: {
        type: DataTypes.STRING,allowNull: false
    },description: {
        type: DataTypes.STRING,allowNull: true
    }
},{ timestamps: false,freezeTableName: true });


module.exports = Weather;

正如我所说,所有表都包含相同的结构和名称,只是下划线后的数字有所区别。

有人可以动态解决吗? 谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)