npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mysql-all

v1.0.2

Published

An easy way to connect to multiple mysql databases

Downloads

11

Readme

mysql-all

An easy way to connect to multiple mysql databases in one shot.

Build Status Coverage Status

Usage.

To use in your project, just execute

npm install mysql-all --save

This will download mysql-all as well as add it as a dependency to your package.json.

Then require mysql-all in your code:

var mysqlAll = require('mysql-all');

//pass in your connections object and return option
var connections = mysqlAll(connections, option);
connections is mandatory and must be an array or object/json.
option is the return type and it is optional.
If option is not specified or specified option is neither "array"
nor "object" return type will be defaulted to object.

Usecases:

For our example usescases, we will use

  1. arrayConfigs as array of our connections
  2. objectConfigs as object who's members are our connections
var arrayConfigs = [
    {
        host     : 'localhost',
        user     : 'me',
        password : 'secret',
        database : 'my_db1'
    },
    {
        host     : 'somehost',
        user     : 'someone',
        password : 'secret',
        database : 'my_db2'
    },
    {
        host     : 'anotherhost',
        user     : 'you',
        password : 'secret',
        database : 'my_db2'
    },
];

var objectConfigs = {
    financedb:{
        host     : 'localhost',
        user     : 'me',
        password : 'secret',
        database : 'my_db1'
    },
    hrdb:{
        host     : 'anotherhost',
        user     : 'you',
        password : 'secret',
        database : 'my_db2'
    }
};

Usecase 1: Array of connections and return type specified as "array".

var connections = require('mysql-all')(arrayConfigs, 'array');

//output connections
[conn1, conn2, conn3]

Usecase 2: Array of connections and return type specified as "object".

var connections = require('mysql-all')(arrayConfigs, 'object');

//outputs an object of connections with host+database name as keys:
{
    localhostmy_db1: 'connection to localhost',
    somehostmy_db2: 'connection to somehost',
    anotherhostmy_db2: 'connection to anotherhost'
}

Usecase 3: Array of connections and return type specified as "object".

var connections = require('mysql-all')(arrayConfigs);

//outputs an object of connections with host+database name as keys:
{
    localhostmy_db1: 'connection to localhost',
    somehostmy_db2: 'connection to somehost',
    anotherhostmy_db2: 'connection to anotherhost'
}

//NOTE: this yields same result as usecase 2

Usecase 4: Object of connections and return type specified as "array".

var connections = require('mysql-all')(objectConfigs, 'array');

//output connections
[conn1, conn2]

//NOTE: this yields similar result as usecase 1

Usecase 5: Object of connections and return type specified as "object".

var connections = require('mysql-all')(objectConfigs, 'object');

//output connections
{
    financedb: 'connection to finance db',
    hrdb: 'connection to hr db'
}

//NOTE: this yields similar result as usecase 3
//except that in this case the keys in the output object will be same as the
// keys in the input connection object/json (objectConfigs) //object/JSON.

//Also not that if 'object' was not specified i.e: require('mysql-all')(objectConfigs);
// output will be same since mysql-all defaults to object when no return option is specified.

Valid connections input types.

  1. Array.

  2. Object literals and

  3. JSON.

OK, Go mysql-all!!