我试图创建一个通过sequelize连接mysql并返回表行的节点模块。 从tes2.js调用test1.js 这个代码块有什么问题?
test1.js
function ftest() {
const Sequelize = require("sequelize");
const sequelize = new Sequelize("dbname", "root", "", {
host: "localhost",
dialect: "mysql"
});
const mordor= sequelize.define("dbtabelename", {
column1: Sequelize.STRING,
column2: Sequelize.STRING,
column3: Sequelize.STRING,
column4: Sequelize.INTEGER
});
sequelize.sync().then(() => {
mordor
.findAll({
raw: true
})
.then(function(rows) {
return rows;
});
});
}
exports.testa = ftest();
test2.js
const conne = require("./test1.js");
var u = conne.testa;
console.log(u);
我希望输出mysql表行,但实际输出未定义。