Sequelize 快速开始

使用例子

var Sequelize = require('sequelize');                              //导入 sequelize 包
var sequelize = new Sequelize('database', 'username', 'password'); //建立数据库连接,必要参数包括 database 数据库名字 username 用户名 password 密码

var User = sequelize.define('user', {                              //定义数据模型
  username: Sequelize.STRING,
  birthday: Sequelize.DATE
});

sequelize.sync().then(function() {                                  //保存数据
  return User.create({
    username: 'janedoe',
    birthday: new Date(1980, 6, 20)
  });
}).then(function(jane) {
  console.log(jane.get({
    plain: true
  }));
});