Noah's Pairwise Manifest

    itsa-mysql-promise

    1.0.5 • Public • Published

    mysql-promise

    Mysql-connections using Promises

    Example getRecord

    "use strict";
     
    var mysqlPromise = require('mysql-promise'),
        dbconfig = {
            "database": "databaseName",
            "user": "databaseUsername",
            "password": "databasePassword"
        },
        databaseConnection = mysqlPromise.getConnection(dbconfig);
     
    // returns a Promise with response = record-object
    getMember = function(id) {
        return databaseConnection.then(function(connection) {
            return connection.getRecords('SELECT * FROM members WHERE id=?', id);
        });
    };

    Example getRecords

    "use strict";
     
    var mysqlPromise = require('mysql-promise'),
        dbconfig = {
            "database": "databaseName",
            "user": "databaseUsername",
            "password": "databasePassword"
        },
        databaseConnection = mysqlPromise.getConnection(dbconfig);
     
    // returns a Promise with response = Array of records
    getMembers = function(teamid) {
        return databaseConnection.then(function(connection) {
            return connection.getRecords('SELECT * FROM members WHERE teamid=?', teamid);
        });
    };

    Example insertGetId

    "use strict";
     
    var mysqlPromise = require('mysql-promise'),
        dbconfig = {
            "database": "databaseName",
            "user": "databaseUsername",
            "password": "databasePassword"
        },
        databaseConnection = mysqlPromise.getConnection(dbconfig);
     
    // returns a Promise with response = key of the new record
    setMember = function(id, name) {
        return databaseConnection.then(function(connection) {
            return connection.insertGetId('INSERT INTO members SET id=?, name=?', [id, name]);
        });
    };

    Example queryPromise

    "use strict";
     
    var mysqlPromise = require('mysql-promise'),
        dbconfig = {
            "database": "databaseName",
            "user": "databaseUsername",
            "password": "databasePassword"
        },
        databaseConnection = mysqlPromise.getConnection(dbconfig);
     
    // returns a Promise with response = {result : array with objects, fields: array with qsl-info}
    updateMember = function(id, name) {
        return databaseConnection.then(function(connection) {
            return connection.queryPromise('UPDATE members SET name=? WHERE id=?', [name, id]);
        });
    };

    Install

    npm i itsa-mysql-promise

    DownloadsWeekly Downloads

    6

    Version

    1.0.5

    License

    New BSD

    Last publish

    Collaborators

    • itsasbreuk