mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
Merge pull request #3469 from sandorfr/tediousConnectionPool
Tedious connection pool
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
// Type definitions for tedious-connection-pool
|
||||
// Project: https://github.com/pekim/tedious-connection-pool
|
||||
// Definitions by: Cyprien Autexier <https://github.com/sandorfr>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="./tedious-connection-pool.d.ts" />
|
||||
|
||||
"use strict";
|
||||
|
||||
import ConnectionPool = require("tedious-connection-pool");
|
||||
import tedious = require("tedious");
|
||||
|
||||
var config: tedious.ConnectionConfig = {
|
||||
userName: "rogier",
|
||||
password: "rogiers password",
|
||||
server: "127.0.0.1",
|
||||
options: {
|
||||
database: "somedb",
|
||||
instance: "someinstance"
|
||||
}
|
||||
};
|
||||
|
||||
var poolConfig : ConnectionPool.PoolConfig = {
|
||||
min: 1,
|
||||
max: 4
|
||||
};
|
||||
|
||||
var pool: ConnectionPool = new ConnectionPool(poolConfig, config);
|
||||
|
||||
pool.on('error', (err: Error) => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
pool.acquire((err: Error, connection: ConnectionPool.PooledConnection) =>{
|
||||
console.log("hurray");
|
||||
connection.beginTransaction((error: Error): void => {}, "some name");
|
||||
connection.rollbackTransaction((error: Error): void => {});
|
||||
connection.commitTransaction((error: Error): void => {});
|
||||
|
||||
|
||||
var request = new tedious.Request("SELECT * FROM foo", (error: Error, rowCount: number): void => {
|
||||
});
|
||||
request.on("row", (row: tedious.ColumnValue[]): void => {
|
||||
});
|
||||
connection.execSql(request);
|
||||
|
||||
connection.release();
|
||||
|
||||
|
||||
pool.drain();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
// Type definitions for tedious-connection-pool
|
||||
// Project: https://github.com/pekim/tedious-connection-pool
|
||||
// Definitions by: Cyprien Autexier <https://github.com/sandorfr>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../tedious/tedious.d.ts" />
|
||||
|
||||
declare module "tedious-connection-pool" {
|
||||
import tedious = require('tedious');
|
||||
|
||||
module tcp {
|
||||
|
||||
/**
|
||||
* Extends Tedious Connection with release function
|
||||
*/
|
||||
export class PooledConnection extends tedious.Connection {
|
||||
/**
|
||||
* If the connection is issued from a connection pool returns the connection to the pool.
|
||||
*/
|
||||
release():void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire function callback signature
|
||||
*/
|
||||
export interface ConnectionCallback {
|
||||
/**
|
||||
* Provides a connection or an error
|
||||
* @param err error if any
|
||||
* @param connection issued from the pool
|
||||
*/
|
||||
(err:Error, connection:PooledConnection): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pool Configuration interface
|
||||
*/
|
||||
export interface PoolConfig {
|
||||
|
||||
/**
|
||||
* Minimum concurrent connections
|
||||
*/
|
||||
min?: number;
|
||||
|
||||
/**
|
||||
* Maximum concurrent connections
|
||||
*/
|
||||
max?: number;
|
||||
|
||||
/**
|
||||
* Defines if logging is activated
|
||||
*/
|
||||
log?: boolean;
|
||||
|
||||
/**
|
||||
* Idle timeout
|
||||
*/
|
||||
idleTimeout?: number;
|
||||
|
||||
/**
|
||||
* Retry delay
|
||||
*/
|
||||
retryDelay?: number;
|
||||
|
||||
/**
|
||||
* Acquire timeout
|
||||
*/
|
||||
acquireTimeout?: number;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tedious Connection Pool Class
|
||||
*/
|
||||
class tcp {
|
||||
|
||||
/**
|
||||
* Connection Pool constructor
|
||||
* @param poolConfig the pool configuration
|
||||
* @param connectionConfig the connection configuration
|
||||
*/
|
||||
constructor(poolConfig:tcp.PoolConfig, connectionConfig:tedious.ConnectionConfig);
|
||||
|
||||
/**
|
||||
* acquires a connection from the pool
|
||||
* @param callback invoked when the connection is retrieved and ready
|
||||
*/
|
||||
acquire(callback:tcp.ConnectionCallback):void;
|
||||
|
||||
/**
|
||||
* listens for a specific connection pool event
|
||||
* @param event the event name
|
||||
* @param callback invoked when the event is raised
|
||||
*/
|
||||
on(event:string, callback:Function):void;
|
||||
|
||||
/**
|
||||
* closes opened connections
|
||||
*/
|
||||
drain():void;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export = tcp;
|
||||
}
|
||||
Reference in New Issue
Block a user