Add node-sqlserver definitions and tests

This commit is contained in:
Boris Yankov
2012-11-02 04:14:18 +02:00
parent bbaed9d9f8
commit 3dff101e1d
3 changed files with 59 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
// Type definitions for msnodesql 0.2
// Project: https://github.com/WindowsAzure/node-sqlserver
// Definitions by: Boris Yankov <https://github.com/borisyankov/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///<reference path='node-0.8.d.ts' />
declare module "msnodesql" {
export function open(connectionString: string, callback: Function): Connection;
export function query(connectionString: string, query: string): StreamEvents;
export function query(connectionString: string, query: string, callback: Function): StreamEvents;
export function query(connectionString: string, query: string, params, callback: Function): StreamEvents;
export function queryRaw(connectionString: string, query: string): StreamEvents;
export function queryRaw(connectionString: string, query: string, callback: Function): StreamEvents;
export function queryRaw(connectionString: string, query: string, params, callback: Function): StreamEvents;
interface Connection { }
interface StreamEvents extends EventEmitter { }
}
+2
View File
@@ -14,6 +14,7 @@ Complete
* [CodeMirror](http://codemirror.net) (by [François de Campredon](https://github.com/fdecampredon))
* [Chosen](http://harvesthq.github.com/chosen/)
* [dynatree](http://code.google.com/p/dynatree/) (by [François de Campredon](https://github.com/fdecampredon))
* [EaselJS](http://www.createjs.com/#!/EaselJS)
* [ember.js](http://emberjs.com/)
* [Express](http://expressjs.com/)
* [Fancybox](http://fancybox.net/)
@@ -36,6 +37,7 @@ Complete
* [Mustache.js](https://github.com/janl/mustache.js)
* [Node.js](http://nodejs.org/) (from TypeScript samples)
* [node_redis](https://github.com/mranney/node_redis)
* [node-sqlserver](https://github.com/WindowsAzure/node-sqlserver)
* [QUnit](http://qunitjs.com/) (by [Diullei Gomes](https://github.com/Diullei))
* [Raphael](http://raphaeljs.com/) (by [CheCoxshall](https://github.com/CheCoxshall))
* [Sammy.js](http://sammyjs.org/)
+35
View File
@@ -0,0 +1,35 @@
/// <reference path="../Definitions/msnodesql-0.2.d.ts" />
import sql = module('msnodesql');
function test_streaming() {
var conn_str = "Driver={SQL Server Native Client 11.0};Server={(local)\\SQLEXPRESS};Database={DBName};Trusted_Connection={Yes};";
var stmt = sql.query(conn_str, "SELECT * from TestTable");
stmt.on('meta', function (meta) { console.log("We've received the metadata"); });
stmt.on('row', function (idx) { console.log("We've started receiving a row"); });
stmt.on('column', function (idx, data, more) { console.log(idx + ":" + data); });
stmt.on('done', function () { console.log("All done!"); });
stmt.on('error', function (err) { console.log("We had an error :-( " + err); });
}
function test_explicit() {
var conn_str = "Driver={SQL Server Native Client 11.0};Server={(localdb)\\v11.0};Database={DBName};Trusted_Connection={Yes};";
sql.open(conn_str, function (err, conn) {
if (err) {
console.log("Error opening the connection!");
return;
}
conn.queryRaw("SELECT * FROM TestTable", function (err, results) {
if (err) {
console.log("Error running query!");
return;
}
for (var i = 0; i < results.rows.length; i++) {
console.log("0:" + results.rows[i][0]);
}
});
});
}