0.4.16 • Published 3 years ago

@overseers/tch v0.4.16

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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.
0.4.16

3 years ago

0.4.15

3 years ago

0.4.14

4 years ago

0.4.13

4 years ago

0.4.12

4 years ago

0.4.10

4 years ago

0.4.11

4 years ago

0.4.9

4 years ago

0.4.8

4 years ago

0.4.7

4 years ago

0.4.5

4 years ago

0.4.6

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.2.2

4 years ago

0.1.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.36

4 years ago

0.0.35

4 years ago

0.0.34

4 years ago

0.0.31

4 years ago

0.0.32

4 years ago

0.0.33

4 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.28

4 years ago

0.0.27

4 years ago

0.0.26

4 years ago

0.0.25

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago