You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

sequelize-transactions

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sequelize-transactions

Sequelize Transactions

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
16
33.33%
Maintainers
1
Weekly downloads
 
Created
Source

sequelize-transactions

Give Sequelize transactions ability

Example Usage:

var Sequelize = require('sequelize');
var useTransaction = require('sequelize-transactions');
var db = null; // sequelize instance

function connectDB(callback) {
	var sequelize = new Sequelize('database', 'username', 'password', {
	    dialect: 'sqlite',
	    storage: dbPath + '/mydb.db',
	    logging: console.log // false
	})

	// Create and attach new Transaction for this adapter
	useTransaction(sequelize);
	

	// Init Models
	// ...
	// if (callback) callback(sequelize);

	db = sequelize;
}

function view_myViewEndPoint() {
    var self = this;

    var name = this.get.name || '';
    var type = this.get.type || '';
        
    // You might also wait transactions to prevent deadlock in some database (ie: SQLite) 
    // using waitTransaction(). Set first param of start() = true
    	
    db.trx.start(true, function(commit, rollback) {

	db.models.Service.find({where: {name: name, type: type}})
	    .success(function(service) {
	
	        if (service) {    
	            db.models.Queue.count({where: ['date(time)=date() AND serviceId=?', service.id]})
	                .success(function(count) {
	
	                    db.models.Queue.create({
	                        start: new Date(),
	                        serviceId: service.id,
	                        queueNo: utils.padDigits(count, 3),
	                    })
	                    .success(function(record) {
	                        
	                        commit(function(error) {
	                            if (!error)   
	                                self.content('OK');
	                            else
	                                self.content('ERROR');
	                        });
	                        
	                    })
	                    .error(function(error) {
	                        rollback();
	                        self.content('ERROR');
	                    });
	
	                })
	                .error(rollback);
	            
	        } else {
	            rollback();
	            self.content('SERVICE NOT FOUND');
	        }
	            
	    });
    });
}

Keywords

mysql

FAQs

Package last updated on 05 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.