Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
sequelize transaction sample
'use strict';
const ruo = require('ruo');
exports.complete = function *(id) {
const t = yield ruo.transaction({autocommit: false});
let bill;
try {
bill = yield ruo.models.Bill.findOne({
where: {
id: id,
status: 'failed',
transaction: t,
const money = yield ruo.models.Money.findOne({
where: {
agentId: bill.agentId,
transaction: t,
yield money.decrement('balance', {by: bill.paid, transaction: t});
bill = yield bill.update({status: 'success'}, {
fileds: ['status'],
transaction: t,
} catch (e) {
throw e;
return bill;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.