Socket
Socket
Sign inDemoInstall

mysql-promise2

Package Overview
Dependencies
12
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mysql-promise2

mysql wrapper with promises and transactions.


Version published
Maintainers
1
Install size
1.75 MB
Created

Readme

Source

mysql-promise2

Standard wrapper around MySQL, function names ending with *Async return Bluebird Promises.

I also added a Bluebird Disposer pool.getTransaction() to ease creating chained Promises in a single transaction which gets automatically committed if everythin's ok or rolled back if there is an error.

var Promise = require('bluebird'),
    mysql = require('mysql-promise2'),
    pool = mysql.createPool({
        connectionLimit: 5,
        host: '', user: '', password: '', database: '',
        //debug: ['ComQueryPacket', 'RowDataPacket']
    });
Promise.using(pool.getTransaction(), function (conn) {
    // everything inside is in a transaction
    return pool.queryAsync(
        "SELECT * FROM data WHERE used = 0 ORDER BY last DESC LIMIT 1"
    ).spread(function (rows, cols) {
        var data = rows[0];
        return pool.queryAsync("UPDATE data SET used = 1 WHERE id = ?", [data.id]
            ).then(function () { return data; });
    });
    // end of the transaction
}).then(function (data) {
    // transaction was a COMMIT
}).catch(function () {
    // transaction was a ROLLBACK
});

ISC license

node MySQL promise Copyright © 2015 Lapo Luchini lapo@lapo.it

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Keywords

FAQs

Last updated on 21 Jan 2015

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc