mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #2944 from Cellule/master
Add express-myconnection definition
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/// <reference path="./express-myconnection.d.ts" />
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// Type definitions for express-myconnection v1.0.4
|
||||
// Project: https://www.npmjs.org/package/express-myconnection
|
||||
// Definitions by: Michael Ferris <https://github.com/Cellule/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../express/express.d.ts" />
|
||||
/// <reference path="../mysql/mysql.d.ts" />
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user