GithubHelp home page GithubHelp logo

pgbouncer's Introduction

pgbouncer

Node.js wrapper for pgbouncer. All methods are asynchronous, using Q promises.

Build Status

Dependency Status devDependency Status

NPM

Basic usage

PgBouncer = require 'pgbouncer'

# create a new PgBouncer instance
# pointing to the location of the pgbouncer.ini file
pgb = new PgBouncer(configFile: '/etc/pgbouncer.ini')

Reading the INI file

pgb.read()
   .then (config) ->

  # [pgbouncer] section

  # config.pgbouncer.listen_port:  5434
  # config.pgbouncer.listen_addr:  '127.0.0.1'
  # config.pgbouncer.auth_type:    'any'  

  # [databases] section

  # config.databases.mydb1:  'postgresql://localhost/db1'
  # config.databases.mydb2:  'postgresql://localhost/db2'

Updating the INI file

config =
  pgbouncer:
    listen_port:  5434
    listen_addr:  '127.0.0.1'
    auth_type:    'any'  
  databases:
    mydb1:  'postgresql://localhost/db1'
    mydb2:  'postgresql://localhost/db2'

pgb.write(config)
   .then -> console.log('done')

Updating the database list only

If you don't need to change the [pgbouncer] section, you can also update the [databases] list only.

databases:
  mydb1:  'postgresql://localhost/db1'
  mydb2:  'postgresql://localhost/db2'

pgb.writeDatabases(databases)
   .then -> console.log('done')

Reloading the config

After updating the INI file, you need to manually trigger a reload command to update the live routing.

pbg.reload()
   .then -> console.log('done')

Getting the current routing status

You can get the current routing status from the pgbouncer show databases command:

pbg.status()
   .then (databases) ->

   # databases[0].name
   # databases[0].host
   # databases[0].port
   # databases[0].database
   # databases[0].force_user
   # databases[0].pool_size

Executing other commands

You can also execute any valid pgbouncer command:

pgb.execute('show users')
   .then (results) -> console.log(results.rows)

Please check pgbouncer documentation for a list of commands.

pgbouncer's People

Contributors

vickvu avatar rprieto avatar anklos 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.