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

@calvium/tedious-connection-pool

v1.0.8

Published

Connection Pool for tedious.

Downloads

23

Readme

tedious-connection-pool

Fork of tedious-connection-pool with pull request #59 merged.

A connection pool for tedious.

Installation

npm install tedious-connection-pool

Description

The only difference from the regular tedious API is how the connection is obtained and released. Rather than creating a connection and then closing it when finished, acquire a connection from the pool and release it when finished. Releasing resets the connection and makes in available for another use.

Once the Tedious Connection object has been acquired, the tedious API can be used with the connection as normal.

Example

var ConnectionPool = require('tedious-connection-pool');
var Request = require('tedious').Request;

var poolConfig = {
    min: 2,
    max: 4,
    log: true
};

var connectionConfig = {
    userName: 'login',
    password: 'password',
    server: 'localhost'
};

//create the pool
var pool = new ConnectionPool(poolConfig, connectionConfig);

pool.on('error', function(err) {
    console.error(err);
});

//acquire a connection
pool.acquire(function (err, connection) {
    if (err) {
        console.error(err);
        return;
    }

    //use the connection as normal
    var request = new Request('select 42', function(err, rowCount) {
        if (err) {
            console.error(err);
            return;
        }

        console.log('rowCount: ' + rowCount);

        //release the connection back to the pool when finished
        connection.release();
    });

    request.on('row', function(columns) {
        console.log('value: ' + columns[0].value);
    });

    connection.execSql(request);
});

When you are finished with the pool, you can drain it (close all connections).

pool.drain();

Class: ConnectionPool

new ConnectionPool(poolConfig, connectionConfig)

  • poolConfig {Object} the pool configuration object
    • min {Number} The minimum of connections there can be in the pool. Default = 10
    • max {Number} The maximum number of connections there can be in the pool. Default = 50
    • idleTimeout {Number} The number of milliseconds before closing an unused connection. Default = 300000
    • retryDelay {Number} The number of milliseconds to wait after a connection fails, before trying again. Default = 5000
    • acquireTimeout {Number} The number of milliseconds to wait for a connection, before returning an error. Default = 60000
    • log {Boolean|Function} Set to true to have debug log written to the console or pass a function to receive the log messages. Default = undefined
  • connectionConfig {Object} The same configuration that would be used to create a tedious Connection.

connectionPool.acquire(callback)

Acquire a Tedious Connection object from the pool.

  • callback(err, connection) {Function} Callback function
  • err {Object} An Error object is an error occurred trying to acquire a connection, otherwise null.
  • connection {Object} A Connection

connectionPool.drain(callback)

Close all pooled connections and stop making new ones. The pool should be discarded after it has been drained.

  • callback() {Function} Callback function

connectionPool.error {event}

The 'error' event is emitted when a connection fails to connect to the SQL Server. The pool will simply retry indefinitely. The application may want to handle errors in a more nuanced way.

Class: Connection

The following method is added to the Tedious Connection object.

Connection.release()

Release the connect back to the pool to be used again