From 2b050502f07fc70409035ce6c8e0867407403323 Mon Sep 17 00:00:00 2001 From: Michael Ferris Date: Wed, 8 Oct 2014 20:37:35 -0400 Subject: [PATCH] Added definition for module express-myconnection --- CONTRIBUTORS.md | 1 + .../express-myconnection-tests.ts | 39 +++++++++++++++++++ .../express-myconnection.d.ts | 29 ++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 express-myconnection/express-myconnection-tests.ts create mode 100644 express-myconnection/express-myconnection.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 4ddfab6e4..caf869bc6 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -86,6 +86,7 @@ All definitions files include a header with the author and editors, so at some p * [expectations](https://github.com/spmason/expectations) (by [vvakame](https://github.com/vvakame)) * [Express](http://expressjs.com/) (by [Boris Yankov](https://github.com/borisyankov)) * [express-session](https://www.npmjs.org/package/express-session) (by [Hiroki Horiuchi](https://github.com/horiuchi/)) +* [express-myconnection](https://www.npmjs.org/package/express-myconnection) (by [Michael Ferris](https://github.com/cellule/) * [Ext JS](http://www.sencha.com/products/extjs/) (by [Brian Kotek](https://github.com/brian428)) * [Fabric.js](http://fabricjs.com/) (by [Oliver Klemencic](https://github.com/oklemencic/)) * [Fancybox](http://fancybox.net/) (by [Boris Yankov](https://github.com/borisyankov)) diff --git a/express-myconnection/express-myconnection-tests.ts b/express-myconnection/express-myconnection-tests.ts new file mode 100644 index 000000000..e789f9cb5 --- /dev/null +++ b/express-myconnection/express-myconnection-tests.ts @@ -0,0 +1,39 @@ +/// + +import express = require('express'); +import mysql = require('mysql'); +import connection = require('express-myconnection'); + +var app = express(); + +app.use( + connection( + mysql, + { + host: 'localhost', + user: 'dbuser', + password: 'password', + port: 3306, + database: 'mydb' + }, + 'single' + ) +); + + +app.use(function list(req: express.Request, res: express.Response, next: Function){ + + req.getConnection(function(err: mysql.IError, connection: mysql.IConnection) { + if (err) return next(err); + + connection.query('SELECT 1 AS RESULT', [], function(err: mysql.IError, results: any) { + if (err) return next(err); + + results[0].RESULT; + // -> 1 + + res.send(200); + }); + }); +}); + diff --git a/express-myconnection/express-myconnection.d.ts b/express-myconnection/express-myconnection.d.ts new file mode 100644 index 000000000..2328f175c --- /dev/null +++ b/express-myconnection/express-myconnection.d.ts @@ -0,0 +1,29 @@ +// Type definitions for express-myconnection v1.0.4 +// Project: https://www.npmjs.org/package/express-myconnection +// Definitions by: Michael Ferris +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +/// + +declare module mysql{ + export interface IConnection {} + export interface IError {} +} + +declare module Express { + + export interface Request { + getConnection?: (callback: (err: mysql.IError, connection: mysql.IConnection) => void) => void; + } +} + +declare module "express-myconnection" { + import express = require('express'); + import mysql = require('mysql'); + + function connection(mysql: mysql.IMySql, dbConfig: mysql.IConnectionConfig, strategy: string): express.RequestHandler; + + export = connection; +} +