节点模块导出返回未定义而不是数据库表行

时间:2019-09-11 20:27:15

标签: mysql node.js requirejs sequelize.js node-modules

我试图创建一个通过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表行,但实际输出未定义。

0 个答案:

没有答案