Promises in Sequelize: how to get results from each promise

前端 未结 3 1437
时光取名叫无心
时光取名叫无心 2021-02-19 19:45

In Sequelize >=1.7 we can use promises

Can you explain for me how can i get values from each user in this code:

var User = sequelize.define(\"user\", {
          


        
3条回答
  •  逝去的感伤
    2021-02-19 20:44

    Try this...

    User
        .sync({ force: true })
        .then(function () {
            return User.create({ username: 'John' });
        })
        .then(function (john) {
            console.log("this is john:");
            console.log(john.values);
            return User.create({ username: 'Jane' });
        })
        .then(function (jane) {
            console.log("this is jane:");
            console.log(jane.values);
            return User.create({ username: 'Pete' });
        })
        .then(function (pete) {
            console.log("we just created 3 users :)");
            console.log("this is pete:");
            console.log(pete.values);
        });
    

提交回复
热议问题