1.0.1 • Published 4 years ago

@cheapreats/txn v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

txn

Flexible transaction management. Learn more about it in our blog post.

Install

$ npm install @cheapreats/txn --save

Quick Start

Before creating a transaction, you must first define all the operations that can be rolled back. For example you might do something like this:

const User = require('./models/User');

function createUser(username, password) {
    let user = null;
    return {
        execute: () => {
            user = new User({username, password});
            await user.save();
        },
        rollback: () => {
            await user.delete();
        },
        retryPolicies: {
            count: 3,
            delay: 1000,
        }
    }
}

Above definition will simply create an user upon execute, and delete the user when rolling back. Retry policy is set to retry maximum 3 times, with delay between being 1000ms.