我尝试使用Sequelize ORM。阅读有关文档,我看到了示例
const Project = sequelize.define('project', {
title: Sequelize.STRING,
description: Sequelize.TEXT
})
const Task = sequelize.define('task', {
title: Sequelize.STRING,
description: Sequelize.TEXT,
deadline: Sequelize.DATE
})
我解决了在shell节点中实际应用的问题。 我在命令行中启动了节点
var sequelize = require('sequelize')
sequelize.define ...
但是结点说我错了,续集没有方法“定义”。 所以我认为现在我的错误在哪里,我错了理解文档
答案 0 :(得分:2)
您需要创建一个sequelize实例:
const Sequelize = require("sequelize");
const sequelize = new Sequelize(
database,
username,
password,
{
host: host,
logging: false,
dialect: "mysql",
port: 3306,
pool: {
max: 5,
min: 0,
idle: 10000
}
}
);
然后定义:
const Project = sequelize.define('project', {
title: Sequelize.STRING,
description: Sequelize.TEXT
})
const Task = sequelize.define('task', {
title: Sequelize.STRING,
description: Sequelize.TEXT,
deadline: Sequelize.DATE
})