我想使用async和upsert以及sequelize事务

时间:2016-02-26 10:00:41

标签: node.js sequelize.js

upsertAsync: function(req, res, next) {

    var datas = req.body;
    var user = req.body.user;

    async.each(datas, function(data, cb) {
        sequelize().transaction({
            autocommit: true
        }, function(t) {
            models.Customer.upsert({
                id: data.id,
                code: data.code,
                createdBy: user.name,
                modifiedBy: user.name
            }, {
                transaction: t
            }).then(function(customer) {
                cb();
            }).
            catch (function(error) {
                t.rollback();

                res.status(500).json(error);
            });

        }, function(err, data) {
            log.debug('error (upsertAsync)', err);
            if (err) {
                t.rollback();
                res.status(500).json(err);
            }
            t.commit();
            res.json({
                responseCode: '200',
                message: 'Customer has been created..!',
                data: data
            });
        });
    });
},

我使用async.each同时将数据插入sqlite数据库。我想要回滚,如果发生任何错误,但它显示错误,这是[TypeError:无法设置属性'选项'未定义的

0 个答案:

没有答案