lib/worker.js
function (connectionInfo, query, params) {
    var connection;

    // Connection validation
    if (typeof connectionInfo.host !== 'string' || connectionInfo.host.length === 0) {
        return respond({
            success: false,
            data: {
                err: 'Bad hostname provided.',
                query: query,
                connection: connectionInfo
            }
        });
    }
    if (typeof connectionInfo.user !== 'string' || connectionInfo.user.length === 0) {
        return respond({
            success: false,
            data: {
                err: 'Bad username provided.',
                query: query,
                connection: connectionInfo
            }
        });
    }

    if (typeof connectionInfo.password !== 'string') {
        return respond({
            success: false,
            data: {
                err: 'Bad password provided.',
                query: query,
                connection: connectionInfo
            }
        });
    }
    if (typeof connectionInfo.database !== 'string' || connectionInfo.database.length === 0) {
        return respond({
            success: false,
            data: {
                err: 'Bad database provided.',
                query: query,
                connection: connectionInfo
            }
        });
    }


    // Return if no sql query specified
    if (query.length === 0) {
        return respond({
            success: false,
            data: {
                err: 'No SQL query specified.'
            }
        });
    }

    // Create the connection to the database
    connection = mysql.createConnection(connectionInfo);

    // Connect to the database
    connection.connect();

    // Do the query
    connection.query(query, params, function (err, rows, fields) {
        // End the connection
        connection.end();

        // Return the error and stop
        if (err) {
            return respond({
                success: false,
                data: {
                    err: err,
                    query: query,
                    connection: connectionInfo
                }

            });
        }

        // Do the callback
        respond({
            success: true,
            data: {
                rows: rows,
                fields: fields
            }
        });
    });
}
function (connectionInfo, query, params) {
    var connection;

    // Connection validation
    if (typeof connectionInfo.host !== 'string' || connectionInfo.host.length === 0) {
        return respond({
            success: false,
            data: {
                err: 'Bad hostname provided.',
                query: query,
                connection: connectionInfo
            }
        });
    }
    if (typeof connectionInfo.user !== 'string' || connectionInfo.user.length === 0) {
        return respond({
            success: false,
            data: {
                err: 'Bad username provided.',
                query: query,
                connection: connectionInfo
            }
        });
    }

    if (typeof connectionInfo.password !== 'string') {
        return respond({
            success: false,
            data: {
                err: 'Bad password provided.',
                query: query,
                connection: connectionInfo
            }
        });
    }
    if (typeof connectionInfo.database !== 'string' || connectionInfo.database.length === 0) {
        return respond({
            success: false,
            data: {
                err: 'Bad database provided.',
                query: query,
                connection: connectionInfo
            }
        });
    }


    // Return if no sql query specified
    if (query.length === 0) {
        return respond({
            success: false,
            data: {
                err: 'No SQL query specified.'
            }
        });
    }

    // Create the connection to the database
    connection = mysql.createConnection(connectionInfo);

    // Connect to the database
    connection.connect();

    // Do the query
    connection.query(query, params, function (err, rows, fields) {
        // End the connection
        connection.end();

        // Return the error and stop
        if (err) {
            return respond({
                success: false,
                data: {
                    err: err,
                    query: query,
                    connection: connectionInfo
                }

            });
        }

        // Do the callback
        respond({
            success: true,
            data: {
                rows: rows,
                fields: fields
            }
        });
    });
}
function ( connectionInfo , query , params ) { var connection ; // Connection validation if ( typeof connectionInfo . host !== 'string' || connectionInfo . host . length === 0 ) { return respond ( { success : false , data : { err : 'Bad hostname provided.' , query : query , connection : connectionInfo } } ) ; } if ( typeof connectionInfo . user !== 'string' || connectionInfo . user . length === 0 ) { return respond ( { success : false , data : { err : 'Bad username provided.' , query : query , connection : connectionInfo } } ) ; } if ( typeof connectionInfo . password !== 'string' ) { return respond ( { success : false , data : { err : 'Bad password provided.' , query : query , connection : connectionInfo } } ) ; } if ( typeof connectionInfo . database !== 'string' || connectionInfo . database . length === 0 ) { return respond ( { success : false , data : { err : 'Bad database provided.' , query : query , connection : connectionInfo } } ) ; } // Return if no sql query specified if ( query . length === 0 ) { return respond ( { success : false , data : { err : 'No SQL query specified.' } } ) ; } // Create the connection to the database connection = mysql . createConnection ( connectionInfo ) ; // Connect to the database connection . connect ( ) ; // Do the query connection . query ( query , params , function ( err , rows , fields ) { // End the connection connection . end ( ) ; // Return the error and stop if ( err ) { return respond ( { success : false , data : { err : err , query : query , connection : connectionInfo } } ) ; } // Do the callback respond ( { success : true , data : { rows : rows , fields : fields } } ) ; } ) ; }
Execute mysql query
@param   {object} connectionInfo Object containing information about the connection
@param   {string} query          The query to execute
@param   {Array}  params         Params to use in the query
@returns {mixed}  Void
Execute mysql query