Giter Site home page Giter Site logo

node-db-pool's Introduction

db-pool Build Status

Easily create a Postgres/MySQL connection pool (postgres only until I get MariaDB/MySQL working on my new Ubuntu 13.04 dev machine).

Behind the scenes it returns an any-db pool which can be used as described here.

Getting Started

Install the module with: npm install db-pool

Configuration

Create a config/database.js containing something like

exports.app1 = {
  defaults: {
    driver: 'postgres',
    min: 5,
    max: 20
  },
  development: {
    database: "development",
    username: "username",
    password: "pass"
  },
  production: {
    database: "production",
    username: "username",
    password: "pass",
    port: 9999
  },
  test: {
    database: "test",
    username: "username",
    password: "pass",
    host: "some.hostname",
    min: 15
  }
};

exports.app1 = {
  ...
  ...
}

Example

var db_pool = require('db-pool');

// Optionally specify an alternative config file (default is to use /config/database.js)
db_pool.config('/config/custom-db-config-file.js');

// Create the default pool (from app1) using NODE_ENV=development|test|production
var test = db_pool.pool();

// Create a pool to a development database
var dev = db_pool.pool('development');
var app1_dev = db_pool.pool('app1.development');

// Create another pool to a different database
var test = db_pool.pool('test');

// Show the known connections. Active ones have pool, connStr and merged default attributes.
console.log(db_pool.debug());

// Run a query
dev.query("SELECT 1", function (err, results) {
  console.log(results);

  // Terminate all active pools
  db_pool.closeAll();
})

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

v0.1.0 Postgres supported

License

Copyright (c) 2013 Mark Selby
Licensed under the MIT license.

node-db-pool's People

Contributors

markselby avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.