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

@overseers/tch

v0.4.16

Published

Tedious Connection Handler

Downloads

50

Readme

Tedious Connection Handler (TCH)

A tedious wrapper to provide some extra functionality with promise based connections. Pooling is built in with normal exec statments and additional pooling capabilities are available using callbacks.


** IN DEVELOPMENT **


Installation

  • NPM

    npm i @overseers/tch

Usage

Creating a connection:

import TCH from '@overseers/tch'

let poolConfig = {
	min: 1,
	max: 5,
	timeout: 10000
}

let tediousConfig = {
	"server": "my.sql.server", 
	"options": 
	{ 
		"port": 9999,
		"database": "myDatabase",
		"encrypt": false
	},
	"authentication": {
		"options": {
			"userName": "myUser",
			"password": "myPass"
			
		},
		"type": "default"
	}
}

TCH.createConnections(poolConfig, tediousConfig);

Using connection after it is created:

import TCH, {Request} from '@overseers/tch'

TCH.createConnections().getConnection()
.then(({connection, release}) => {
	let data: any[] = [];
        let request = new Request('select * from dbo.Test', (error, rowCount, rows) => {
            release();
            if(error){
                console.error('ERROR', error);
            } else {
                if(rowCount === data.length){
                    console.log(JSON.stringify(data), rows);
                } else {
                    console.error('Invalid Response')
                }
            }
        });
    
        request.on('row', (columns) => {
            data.push(columns.reduce((acc, next) => {
                acc[next.metadata.colName] = next.value;
                return acc;
            }, {}));
        })
    
        connection.execSql(request)
})
.catch(console.error)

General Purpose Use

import TCH, {Request} from '@overseers/tch';

TCH.getConnection()
.then(connection => {
	//your request goes here
}).catch(console.error);

Shorthand Handled Request

import TCH, { Request } from '@overseers/tch'

TCH.getHandledRequest('select * from dbo.Test', [], []).then(console.log).catch(console.error);

Async

import TCH, {Request} from '@overseers/tch';

(async () => {
	const connection = await TCH.getConnection();
	//do what you want with connection;

	const result = await TCH.getHandledRequest('select * from dbo.Test', [], []);
})()

INFO

  • The DatabaseConnection will keep the minimum amount of connections alive. Any connection created between the minimum and maximum will exist for as long as it is used until it is released and unused for the alotted timeout.
  • When working with the connection itself, you are provided the release() function. The connection will remain busy until you call the release function. If you fail to call it after you are finished then the module will continue to create new connections up to your defined max count. After that, it will wait until one is available. During this wait, there is a 30ms timeout to check for a available connection.
  • When working with large max pools, you can hit your maximum amount of connections fairly quickly. However, if the connections are never used then they will automatically be disposed of by a 5s timer that runs to clean up connections.