如何将Sequelize模型与预定义表同步

时间:2016-09-04 13:40:49

标签: sequelize.js

我了解下面的代码是在数据库中创建NEW表并将其称为User,然后向其中添加数据。 我在我的数据中已存在表User,我只想做一个与此表同步的模型,我该怎么办?

var Sequelize = require('sequelize');
var sequelize = new Sequelize('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
    }));
});

1 个答案:

答案 0 :(得分:0)

看起来唯一的选择就是写$fourDaysAgo = new DateTime('-4 days'); // some code for xml feed $xmlDate = //(string) $item[$i]->date; $date = new DateTime($xmlDate); if($fourDaysAgo->format('Y-m-d') == $date->format('Y-m-d') ) { echo 'Store in database'; }