mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-25 11:11:46 +08:00
+67
-1
@@ -71,8 +71,74 @@ var connection: sql.Connection = new sql.Connection(config, function (err: any)
|
||||
console.error('Error happened calling Query: ' + err.name + " " + err.message);
|
||||
}
|
||||
else {
|
||||
console.info(requestStoredProcedureWithOutput.parameters.output.value);
|
||||
console.info(requestStoredProcedureWithOutput.parameters['output'].value);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function test_table() {
|
||||
var table = new sql.Table('#temp_table');
|
||||
|
||||
table.create = true;
|
||||
|
||||
table.columns.add('name', sql.VarChar(sql.MAX), { nullable: false });
|
||||
table.columns.add('type', sql.Int, { nullable: false });
|
||||
table.columns.add('amount', sql.Decimal(7, 2), { nullable: false });
|
||||
|
||||
table.rows.add('name', 42, 3.50);
|
||||
table.rows.add('name2', 7, 3.14);
|
||||
}
|
||||
|
||||
|
||||
function test_promise_returns() {
|
||||
// Methods return a promises if the callback is omitted.
|
||||
var connection: sql.Connection = new sql.Connection(config);
|
||||
connection.connect().then(() => { });
|
||||
connection.close().then(() => { });
|
||||
|
||||
var preparedStatment = new sql.PreparedStatement(connection);
|
||||
preparedStatment.prepare("SELECT @myValue").then(() => { });
|
||||
preparedStatment.execute({ myValue: 1 }).then((recordSet) => { });
|
||||
preparedStatment.unprepare().then(() => { });
|
||||
|
||||
var transaction = new sql.Transaction(connection);
|
||||
transaction.begin().then(() => { });
|
||||
transaction.commit().then(() => { });
|
||||
transaction.rollback().then(() => { });
|
||||
|
||||
var request = new sql.Request();
|
||||
request.batch('create procedure #temporary as select * from table').then((recordset) => { });
|
||||
request.bulk(new sql.Table("table_name")).then(() => { });
|
||||
request.query('SELECT 1').then((recordset) => { });
|
||||
request.execute('procedure_name').then((recordset) => { });
|
||||
}
|
||||
|
||||
|
||||
function test_request_constructor() {
|
||||
// Request can be constructed with a connection, preparedStatment, transaction or no arguments
|
||||
var connection: sql.Connection = new sql.Connection(config);
|
||||
var preparedStatment = new sql.PreparedStatement(connection);
|
||||
var transaction = new sql.Transaction(connection);
|
||||
|
||||
var request1 = new sql.Request(connection);
|
||||
var request2 = new sql.Request(preparedStatment);
|
||||
var request3 = new sql.Request(transaction);
|
||||
var request4 = new sql.Request();
|
||||
}
|
||||
|
||||
function test_classes_extend_eventemitter() {
|
||||
var connection: sql.Connection = new sql.Connection(config);
|
||||
var transaction = new sql.Transaction();
|
||||
var request = new sql.Request();
|
||||
var preparedStatment = new sql.PreparedStatement();
|
||||
|
||||
connection.on('connect', () => { });
|
||||
transaction.on('begin', () => { });
|
||||
transaction.on('commit', () => { });
|
||||
transaction.on('rollback', () => { });
|
||||
request.on('done', () => { });
|
||||
request.on('error', () => { });
|
||||
|
||||
preparedStatment.on('error', () => { })
|
||||
}
|
||||
Vendored
+208
-62
@@ -1,53 +1,131 @@
|
||||
// Type definitions for mssql
|
||||
// Type definitions for mssql v2.2.0
|
||||
// Project: https://www.npmjs.com/package/mssql
|
||||
// Definitions by: COLSA Corporation <http://www.colsa.com/>
|
||||
// Definitions by: COLSA Corporation <http://www.colsa.com/>, Ben Farr <https://github.com/jaminfarr>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
/// <reference path="../es6-promise/es6-promise.d.ts" />
|
||||
|
||||
declare module "mssql" {
|
||||
import events = require('events');
|
||||
|
||||
export var Date: any;
|
||||
export var DateTime: any;
|
||||
export var DateTime2: any;
|
||||
export var DateTimeOffset: any;
|
||||
export var SmallDateTime: any;
|
||||
export var Time: any;
|
||||
export var Char: any;
|
||||
export var VarChar:any;
|
||||
export var NChar: any;
|
||||
export var NVarChar: any;
|
||||
export var Text:any;
|
||||
export var NText:any;
|
||||
export var Xml: any;
|
||||
export var TinyInt:any;
|
||||
export var SmallInt:any;
|
||||
export var Int: any;
|
||||
export var BigInt:any;
|
||||
export var Decimal:any;
|
||||
export var Float:any;
|
||||
export var Real:any;
|
||||
export var SmallMoney:any;
|
||||
export var Money:any;
|
||||
export var Numeric:any;
|
||||
export var Bit: any;
|
||||
export var Binary: any;
|
||||
export var VarBinary: any;
|
||||
export var TVP: any;
|
||||
export var UniqueIdentifier: any;
|
||||
export var Image: any;
|
||||
export var UDT: any;
|
||||
export var Geography: any;
|
||||
export var Geometry: any;
|
||||
type sqlTypeWithNoParams = { type: sqlTypeFactoryWithNoParams }
|
||||
type sqlTypeWithLength = { type: sqlTypeFactoryWithLength, length: number }
|
||||
type sqlTypeWithScale = { type: sqlTypeFactoryWithScale, scale: number }
|
||||
type sqlTypeWithPrecisionScale = { type: sqlTypeFactoryWithPrecisionScale, precision: number, scale: number }
|
||||
type sqlTypeWithTvpType = { type: sqlTypeFactoryWithTvpType, tvpType: any }
|
||||
|
||||
export interface options {
|
||||
type sqlTypeFactoryWithNoParams = () => sqlTypeWithNoParams;
|
||||
type sqlTypeFactoryWithLength = (length?: number) => sqlTypeWithLength;
|
||||
type sqlTypeFactoryWithScale = (scale?: number) => sqlTypeWithScale;
|
||||
type sqlTypeFactoryWithPrecisionScale = (precision?: number, scale?: number) => sqlTypeWithPrecisionScale;
|
||||
type sqlTypeFactoryWithTvpType = (tvpType: any) => sqlTypeWithTvpType;
|
||||
|
||||
export var VarChar: sqlTypeFactoryWithLength;
|
||||
export var NVarChar: sqlTypeFactoryWithLength;
|
||||
export var Text: sqlTypeFactoryWithNoParams;
|
||||
export var Int: sqlTypeFactoryWithNoParams;
|
||||
export var BigInt: sqlTypeFactoryWithNoParams;
|
||||
export var TinyInt: sqlTypeFactoryWithNoParams;
|
||||
export var SmallInt: sqlTypeFactoryWithNoParams;
|
||||
export var Bit: sqlTypeFactoryWithNoParams;
|
||||
export var Float: sqlTypeFactoryWithNoParams;
|
||||
export var Numeric: sqlTypeFactoryWithPrecisionScale;
|
||||
export var Decimal: sqlTypeFactoryWithPrecisionScale;
|
||||
export var Real: sqlTypeFactoryWithNoParams;
|
||||
export var Date: sqlTypeFactoryWithNoParams;
|
||||
export var DateTime: sqlTypeFactoryWithNoParams;
|
||||
export var DateTime2: sqlTypeFactoryWithScale;
|
||||
export var DateTimeOffset: sqlTypeFactoryWithScale;
|
||||
export var SmallDateTime: sqlTypeFactoryWithNoParams;
|
||||
export var Time: sqlTypeFactoryWithScale;
|
||||
export var UniqueIdentifier: sqlTypeFactoryWithNoParams;
|
||||
export var SmallMoney: sqlTypeFactoryWithNoParams;
|
||||
export var Money: sqlTypeFactoryWithNoParams;
|
||||
export var Binary: sqlTypeFactoryWithNoParams;
|
||||
export var VarBinary: sqlTypeFactoryWithLength;
|
||||
export var Image: sqlTypeFactoryWithNoParams;
|
||||
export var Xml: sqlTypeFactoryWithNoParams;
|
||||
export var Char: sqlTypeFactoryWithLength;
|
||||
export var NChar: sqlTypeFactoryWithLength;
|
||||
export var NText: sqlTypeFactoryWithNoParams;
|
||||
export var TVP: sqlTypeFactoryWithTvpType;
|
||||
export var UDT: sqlTypeFactoryWithNoParams;
|
||||
export var Geography: sqlTypeFactoryWithNoParams;
|
||||
export var Geometry: sqlTypeFactoryWithNoParams;
|
||||
|
||||
export var TYPES: {
|
||||
VarChar: sqlTypeFactoryWithLength;
|
||||
NVarChar: sqlTypeFactoryWithLength;
|
||||
Text: sqlTypeFactoryWithNoParams;
|
||||
Int: sqlTypeFactoryWithNoParams;
|
||||
BigInt: sqlTypeFactoryWithNoParams;
|
||||
TinyInt: sqlTypeFactoryWithNoParams;
|
||||
SmallInt: sqlTypeFactoryWithNoParams;
|
||||
Bit: sqlTypeFactoryWithNoParams;
|
||||
Float: sqlTypeFactoryWithNoParams;
|
||||
Numeric: sqlTypeFactoryWithPrecisionScale;
|
||||
Decimal: sqlTypeFactoryWithPrecisionScale;
|
||||
Real: sqlTypeFactoryWithNoParams;
|
||||
Date: sqlTypeFactoryWithNoParams;
|
||||
DateTime: sqlTypeFactoryWithNoParams;
|
||||
DateTime2: sqlTypeFactoryWithScale;
|
||||
DateTimeOffset: sqlTypeFactoryWithScale;
|
||||
SmallDateTime: sqlTypeFactoryWithNoParams;
|
||||
Time: sqlTypeFactoryWithScale;
|
||||
UniqueIdentifier: sqlTypeFactoryWithNoParams;
|
||||
SmallMoney: sqlTypeFactoryWithNoParams;
|
||||
Money: sqlTypeFactoryWithNoParams;
|
||||
Binary: sqlTypeFactoryWithNoParams;
|
||||
VarBinary: sqlTypeFactoryWithLength;
|
||||
Image: sqlTypeFactoryWithNoParams;
|
||||
Xml: sqlTypeFactoryWithNoParams;
|
||||
Char: sqlTypeFactoryWithLength;
|
||||
NChar: sqlTypeFactoryWithLength;
|
||||
NText: sqlTypeFactoryWithNoParams;
|
||||
TVP: sqlTypeFactoryWithTvpType;
|
||||
UDT: sqlTypeFactoryWithNoParams;
|
||||
Geography: sqlTypeFactoryWithNoParams;
|
||||
Geometry: sqlTypeFactoryWithNoParams;
|
||||
};
|
||||
|
||||
export var MAX: number;
|
||||
export var fix: boolean;
|
||||
export var Promise: any;
|
||||
|
||||
|
||||
interface IMap extends Array<{js: any, sql: any }> {
|
||||
register(jstype: any, sql: any): void;
|
||||
}
|
||||
|
||||
export var map: IMap;
|
||||
|
||||
export var DRIVERS: string[];
|
||||
|
||||
type recordSet = any;
|
||||
type IIsolationLevel = number;
|
||||
|
||||
export var ISOLATION_LEVEL: {
|
||||
READ_UNCOMMITTED: IIsolationLevel
|
||||
READ_COMMITTED: IIsolationLevel
|
||||
REPEATABLE_READ: IIsolationLevel
|
||||
SERIALIZABLE: IIsolationLevel
|
||||
SNAPSHOT: IIsolationLevel
|
||||
}
|
||||
|
||||
export interface IOptions {
|
||||
encrypt: boolean;
|
||||
}
|
||||
|
||||
export interface pool {
|
||||
|
||||
export interface IPool {
|
||||
min: number;
|
||||
max: number;
|
||||
idleTimeoutMillis: number;
|
||||
}
|
||||
|
||||
export var pool: IPool;
|
||||
|
||||
export interface config {
|
||||
driver?: string;
|
||||
user?: string;
|
||||
@@ -59,18 +137,26 @@ declare module "mssql" {
|
||||
connectionTimeout?: number;
|
||||
requestTimeout?: number;
|
||||
stream?: boolean;
|
||||
options?: options;
|
||||
pool?: pool;
|
||||
|
||||
options?: IOptions;
|
||||
pool?: IPool;
|
||||
}
|
||||
|
||||
export class Connection {
|
||||
|
||||
export class Connection extends events.EventEmitter {
|
||||
public connected: boolean;
|
||||
public connecting: boolean;
|
||||
public driver: string;
|
||||
public constructor(config: config, callback?: (err?: any) => void);
|
||||
public connect(): Promise<void>;
|
||||
public connect(callback: (err: any) => void): void;
|
||||
public close(): Promise<void>;
|
||||
public close(callback: (err: any) => void): void;
|
||||
}
|
||||
|
||||
public connect(callback?: (err?: any) => void): void;
|
||||
|
||||
public close(): void;
|
||||
export class ConnectionError implements Error {
|
||||
constructor(message: string, code?: any)
|
||||
public name: string;
|
||||
public message: string;
|
||||
public code: string;
|
||||
}
|
||||
|
||||
class columns {
|
||||
@@ -78,7 +164,7 @@ declare module "mssql" {
|
||||
}
|
||||
|
||||
class rows {
|
||||
public add(row: any): void;
|
||||
public add(...row: any[]): void;
|
||||
}
|
||||
|
||||
export class Table {
|
||||
@@ -86,37 +172,97 @@ declare module "mssql" {
|
||||
public columns: columns;
|
||||
public rows: rows;
|
||||
public constructor(tableName: string);
|
||||
|
||||
}
|
||||
|
||||
export class Request {
|
||||
interface IRequestParameters {
|
||||
[name: string]: {
|
||||
name: string;
|
||||
type: any;
|
||||
io: number;
|
||||
value: any;
|
||||
length: number;
|
||||
scale: number;
|
||||
precision: number;
|
||||
tvpType: any;
|
||||
}
|
||||
}
|
||||
|
||||
export class Request extends events.EventEmitter {
|
||||
public connection: Connection;
|
||||
public transaction: Transaction;
|
||||
public pstatement: PreparedStatement;
|
||||
public parameters: IRequestParameters;
|
||||
public verbose: boolean;
|
||||
public multiple: boolean;
|
||||
public canceled: boolean;
|
||||
public stream: any;
|
||||
public constructor(connection?: Connection);
|
||||
public execute(procedure: string, callback?: (err?: any, recordsets?: any, returnValue?: any) => void): void;
|
||||
public constructor(transaction: Transaction);
|
||||
public constructor(preparedStatement: PreparedStatement);
|
||||
public execute(procedure: string): Promise<recordSet>;
|
||||
public execute(procedure: string, callback: (err?: any, recordsets?: any, returnValue?: any) => void): void;
|
||||
public input(name: string, value: any): void;
|
||||
public input(name: string, type: any, value: any): void;
|
||||
public output(name: string, type: any, value?: any): void;
|
||||
public pipe(stream: any): void;
|
||||
public query(command: string, callback?: (err?: any, recordset?: any) => void): void;
|
||||
public batch(batch: string, callback?: (err?: any, recordset?: any) => void): void;
|
||||
public bulk(table: Table, callback?: (err?: any, rowCount?: any) => void): void;
|
||||
public pipe(stream: NodeJS.WritableStream): void;
|
||||
public query(command: string): Promise<void>;
|
||||
public query(command: string, callback: (err?: any, recordset?: any) => void): void;
|
||||
public batch(batch: string): Promise<recordSet>;
|
||||
public batch(batch: string, callback: (err?: any, recordset?: any) => void): void;
|
||||
public bulk(table: Table): Promise<void>;
|
||||
public bulk(table: Table, callback: (err: any, rowCount: any) => void): void;
|
||||
public cancel(): void;
|
||||
public parameters: any;
|
||||
}
|
||||
|
||||
export class Transaction {
|
||||
export class RequestError implements Error {
|
||||
constructor(message: string, code?: any)
|
||||
public name: string;
|
||||
public message: string;
|
||||
public code: string;
|
||||
}
|
||||
|
||||
export class Transaction extends events.EventEmitter {
|
||||
public connection: Connection;
|
||||
public isolationLevel: IIsolationLevel;
|
||||
public constructor(connection?: Connection);
|
||||
public begin(isolationLevel?: any, callback?: (err?: any) => void): void;
|
||||
public begin(callback?: (err?: any) => void): void;
|
||||
public commit(callback?: (err?: any) => void): void;
|
||||
public rollback(callback?: (err?: any) => void): void;
|
||||
public begin(isolationLevel?: IIsolationLevel): Promise<void>;
|
||||
public begin(isolationLevel?: IIsolationLevel, callback?: (err?: any) => void): void;
|
||||
public commit(): Promise<void>;
|
||||
public commit(callback: (err?: any) => void): void;
|
||||
public rollback(): Promise<void>;
|
||||
public rollback(callback: (err?: any) => void): void;
|
||||
}
|
||||
|
||||
export class PreparedStatement {
|
||||
export class TransactionError implements Error {
|
||||
constructor(message: string, code?: any)
|
||||
public name: string;
|
||||
public message: string;
|
||||
public code: string;
|
||||
}
|
||||
|
||||
export class PreparedStatement extends events.EventEmitter {
|
||||
public connection: Connection;
|
||||
public transaction: Transaction;
|
||||
public prepared: boolean;
|
||||
public statement: string;
|
||||
public parameters: IRequestParameters;
|
||||
public multiple: boolean;
|
||||
public stream: any;
|
||||
public constructor(connection?: Connection);
|
||||
public input(name: string, type: any): void;
|
||||
public output(name: string, type: any): void;
|
||||
public prepare(statement: string, callback?: (err?: any) => void): void;
|
||||
public execute(values: any, callback?: (err?: any) => void): void;
|
||||
public unprepare(callback?: (err?: any) => void): void;
|
||||
public prepare(statement?: string): Promise<void>;
|
||||
public prepare(statement?: string, callback?: (err?: any) => void): void;
|
||||
public execute(values: Object): Promise<recordSet>;
|
||||
public execute(values: Object, callback: (err: any, recordSet: recordSet) => void): void;
|
||||
public unprepare(): Promise<void>;
|
||||
public unprepare(callback: (err?: any) => void): void;
|
||||
}
|
||||
|
||||
export class PreparedStatementError implements Error {
|
||||
constructor(message: string, code?: any)
|
||||
public name: string;
|
||||
public message: string;
|
||||
public code: string;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user