From 20a7a9419ac98fd782e2ad6abb763f6ac6ba0aa9 Mon Sep 17 00:00:00 2001 From: ColsaCorp Date: Wed, 18 Mar 2015 22:56:48 -0500 Subject: [PATCH 1/2] Create mssql.d.ts Initial creation of MSSQL database connector for Node.js defintion --- mssql/mssql.d.ts | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 mssql/mssql.d.ts diff --git a/mssql/mssql.d.ts b/mssql/mssql.d.ts new file mode 100644 index 000000000..dcdd0f700 --- /dev/null +++ b/mssql/mssql.d.ts @@ -0,0 +1,96 @@ +// Type definitions for mssql +// Project: https://www.npmjs.com/package/mssql +// Definitions by: COLSA Corporation +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "mssql" { + + export var DateTime: any; + export var NVarChar: any; + export var Int: any; + export var Bit: any; + export var VarBinary: any; + export var TVP: any; + + export interface options { + encrypt: boolean; + } + + export interface pool { + min: number; + max: number; + idleTimeoutMillis: number; + } + + export interface config { + driver?: string; + user?: string; + password?: string; + server: string; + port?: number; + domain?: string; + database: string; + connectionTimeout?: number; + requestTimeout?: number; + stream?: boolean; + options?: options; + pool?: pool; + + } + + export class Connection { + + public constructor(config: config, callback?: (err?: any) => void); + + public connect(callback?: (err?: any) => void); + + public close(); + } + + class columns { + public add(name: string, type: any, options: any); + } + + class rows { + public add(any); + } + + export class Table { + public create: boolean; + public columns: columns; + public rows: rows; + public constructor(tableName: string); + + } + + export class Request { + public constructor(connection?: Connection); + public execute(procedure: string, callback?: (err?: any, recordsets?: any, returnValue?: any) => void); + public input(name: string, value: any); + public input(name: string, type: any, value: any); + public output(name: string, type: any, value?: any); + public pipe(stream: any); + public query(command: string, callback?: (err?: any, recordset?: any) => void); + public batch(batch: string, callback?: (err?: any, recordset?: any) => void); + public bulk(table: Table, callback?: (err?: any, rowCount?: any) => void); + public cancel(); + public parameters: any; + } + + export class Transaction { + public constructor(connection?: Connection); + public begin(isolationLevel?: any, callback?: (err?: any) => void); + public begin(callback?: (err?: any) => void); + public commit(callback?: (err?: any) => void); + public rollback(callback?: (err?: any) => void); + } + + export class PreparedStatement { + public constructor(connection?: Connection); + public input(name: string, type: any); + public output(name: string, type: any); + public prepare(statement: string, callback?: (err?: any) => void); + public execute(values: any, callback?: (err?: any) => void); + public unprepare(callback?: (err?: any) => void); + } +} From d0087d3ab84b49c80cc4770117526774403b889c Mon Sep 17 00:00:00 2001 From: ColsaCorp Date: Wed, 18 Mar 2015 22:57:36 -0500 Subject: [PATCH 2/2] Create mssql-tests.ts Tests for MSSQL database connector for Node.js --- mssql/mssql-tests.ts | 70 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 mssql/mssql-tests.ts diff --git a/mssql/mssql-tests.ts b/mssql/mssql-tests.ts new file mode 100644 index 000000000..5a7e3e305 --- /dev/null +++ b/mssql/mssql-tests.ts @@ -0,0 +1,70 @@ +/// +/// + +import sql = require('mssql'); + +var config: sql.config = { + user: 'user', + password: 'password', + server: 'ip', + database: 'database', + connectionTimeout: 10000, + options: { + encrypt: true + } +} + +var connection: sql.Connection = new sql.Connection(config, function (err: any) { + if (err != null) { + console.warn("Issue with connecting to SQL Server!"); + } + else { + var requestQuery = new sql.Request(connection); + + var getArticlesQuery = "SELECT * FROM TABLE"; + + requestQuery.query(getArticlesQuery, function (err, recordSet) { + if (err) { + console.error('Error happened calling Query: ' + err.name + " " + err.message); + + } + // checking to see if the articles returned as at least one. + else if (recordSet.length > 0) { + } + }); + + var requestStoredProcedure = new sql.Request(connection); + var testId: number = 0; + var testString: string = 'test'; + + requestStoredProcedure.input('pId', testId); + requestStoredProcedure.input('pString', testString); + + + requestStoredProcedure.execute('StoredProcedureName', function (err, recordsets, returnValue) { + if (err != null) { + console.error('Error happened calling Query: ' + err.name + " " + err.message); + } + else { + console.info(returnValue); + } + }); + + var requestStoredProcedureWithOutput = new sql.Request(connection); + var testId: number = 0; + var testString: string = 'test'; + + requestStoredProcedure.input('pId', testId); + requestStoredProcedure.input('pString', testString); + requestStoredProcedure.output('output', sql.Int); + + requestStoredProcedure.execute('StoredProcedureName', function (err, recordsets, returnValue) { + if (err != null) { + console.error('Error happened calling Query: ' + err.name + " " + err.message); + } + else { + console.info(requestStoredProcedureWithOutput.parameters.output.value); + } + }); + } +});