diff --git a/mssql/index.d.ts b/mssql/index.d.ts
index 8aaca045e2..5f013e33a1 100644
--- a/mssql/index.d.ts
+++ b/mssql/index.d.ts
@@ -1,91 +1,96 @@
// Type definitions for mssql 3.3
// Project: https://www.npmjs.com/package/mssql
-// Definitions by: COLSA Corporation , Ben Farr , Vitor Buzinaro , Matt Richardson
+// Definitions by: COLSA Corporation , Ben Farr , Vitor Buzinaro , Matt Richardson , Jørgen Elgaard Larsen
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
///
import events = require('events');
+export interface ISqlType {
+ type: ISqlTypeFactory;
+}
+export interface ISqlTypeWithNoParams extends ISqlType { type: ISqlTypeFactoryWithNoParams }
+export interface ISqlTypeWithLength extends ISqlType { type: ISqlTypeFactoryWithLength; length: number }
+export interface ISqlTypeWithScale extends ISqlType { type: ISqlTypeFactoryWithScale; scale: number }
+export interface ISqlTypeWithPrecisionScale extends ISqlType { type: ISqlTypeFactoryWithPrecisionScale; precision: number, scale: number }
+export interface ISqlTypeWithTvpType extends ISqlType { type: ISqlTypeFactoryWithTvpType; tvpType: 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 ISqlTypeFactory {
+}
+export interface ISqlTypeFactoryWithNoParams extends ISqlTypeFactory { (): ISqlTypeWithNoParams; }
+export interface ISqlTypeFactoryWithLength extends ISqlTypeFactory { (length?: number): ISqlTypeWithLength }
+export interface ISqlTypeFactoryWithScale extends ISqlTypeFactory { (scale?: number): ISqlTypeWithScale }
+export interface ISqlTypeFactoryWithPrecisionScale extends ISqlTypeFactory { (precision?: number, scale?: number): ISqlTypeWithPrecisionScale; }
+export interface ISqlTypeFactoryWithTvpType extends ISqlTypeFactory { (tvpType: any): ISqlTypeWithTvpType }
-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 declare var VarChar: sqlTypeFactoryWithLength;
-export declare var NVarChar: sqlTypeFactoryWithLength;
-export declare var Text: sqlTypeFactoryWithNoParams;
-export declare var Int: sqlTypeFactoryWithNoParams;
-export declare var BigInt: sqlTypeFactoryWithNoParams;
-export declare var TinyInt: sqlTypeFactoryWithNoParams;
-export declare var SmallInt: sqlTypeFactoryWithNoParams;
-export declare var Bit: sqlTypeFactoryWithNoParams;
-export declare var Float: sqlTypeFactoryWithNoParams;
-export declare var Numeric: sqlTypeFactoryWithPrecisionScale;
-export declare var Decimal: sqlTypeFactoryWithPrecisionScale;
-export declare var Real: sqlTypeFactoryWithNoParams;
-export declare var Date: sqlTypeFactoryWithNoParams;
-export declare var DateTime: sqlTypeFactoryWithNoParams;
-export declare var DateTime2: sqlTypeFactoryWithScale;
-export declare var DateTimeOffset: sqlTypeFactoryWithScale;
-export declare var SmallDateTime: sqlTypeFactoryWithNoParams;
-export declare var Time: sqlTypeFactoryWithScale;
-export declare var UniqueIdentifier: sqlTypeFactoryWithNoParams;
-export declare var SmallMoney: sqlTypeFactoryWithNoParams;
-export declare var Money: sqlTypeFactoryWithNoParams;
-export declare var Binary: sqlTypeFactoryWithNoParams;
-export declare var VarBinary: sqlTypeFactoryWithLength;
-export declare var Image: sqlTypeFactoryWithNoParams;
-export declare var Xml: sqlTypeFactoryWithNoParams;
-export declare var Char: sqlTypeFactoryWithLength;
-export declare var NChar: sqlTypeFactoryWithLength;
-export declare var NText: sqlTypeFactoryWithNoParams;
-export declare var TVP: sqlTypeFactoryWithTvpType;
-export declare var UDT: sqlTypeFactoryWithNoParams;
-export declare var Geography: sqlTypeFactoryWithNoParams;
-export declare var Geometry: sqlTypeFactoryWithNoParams;
+export declare var VarChar: ISqlTypeFactoryWithLength;
+export declare var NVarChar: ISqlTypeFactoryWithLength;
+export declare var Text: ISqlTypeFactoryWithNoParams;
+export declare var Int: ISqlTypeFactoryWithNoParams;
+export declare var BigInt: ISqlTypeFactoryWithNoParams;
+export declare var TinyInt: ISqlTypeFactoryWithNoParams;
+export declare var SmallInt: ISqlTypeFactoryWithNoParams;
+export declare var Bit: ISqlTypeFactoryWithNoParams;
+export declare var Float: ISqlTypeFactoryWithNoParams;
+export declare var Numeric: ISqlTypeFactoryWithPrecisionScale;
+export declare var Decimal: ISqlTypeFactoryWithPrecisionScale;
+export declare var Real: ISqlTypeFactoryWithNoParams;
+export declare var Date: ISqlTypeFactoryWithNoParams;
+export declare var DateTime: ISqlTypeFactoryWithNoParams;
+export declare var DateTime2: ISqlTypeFactoryWithScale;
+export declare var DateTimeOffset: ISqlTypeFactoryWithScale;
+export declare var SmallDateTime: ISqlTypeFactoryWithNoParams;
+export declare var Time: ISqlTypeFactoryWithScale;
+export declare var UniqueIdentifier: ISqlTypeFactoryWithNoParams;
+export declare var SmallMoney: ISqlTypeFactoryWithNoParams;
+export declare var Money: ISqlTypeFactoryWithNoParams;
+export declare var Binary: ISqlTypeFactoryWithNoParams;
+export declare var VarBinary: ISqlTypeFactoryWithLength;
+export declare var Image: ISqlTypeFactoryWithNoParams;
+export declare var Xml: ISqlTypeFactoryWithNoParams;
+export declare var Char: ISqlTypeFactoryWithLength;
+export declare var NChar: ISqlTypeFactoryWithLength;
+export declare var NText: ISqlTypeFactoryWithNoParams;
+export declare var TVP: ISqlTypeFactoryWithTvpType;
+export declare var UDT: ISqlTypeFactoryWithNoParams;
+export declare var Geography: ISqlTypeFactoryWithNoParams;
+export declare var Geometry: ISqlTypeFactoryWithNoParams;
export declare 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;
+ VarChar: ISqlTypeFactoryWithLength;
+ NVarChar: ISqlTypeFactoryWithLength;
+ Text: ISqlTypeFactoryWithNoParams;
+ Int: ISqlTypeFactoryWithNoParams;
+ BigInt: ISqlTypeFactoryWithNoParams;
+ TinyInt: ISqlTypeFactoryWithNoParams;
+ SmallInt: ISqlTypeFactoryWithNoParams;
+ Bit: ISqlTypeFactoryWithNoParams;
+ Float: ISqlTypeFactoryWithNoParams;
+ Numeric: ISqlTypeFactoryWithPrecisionScale;
+ Decimal: ISqlTypeFactoryWithPrecisionScale;
+ Real: ISqlTypeFactoryWithNoParams;
+ Date: ISqlTypeFactoryWithNoParams;
+ DateTime: ISqlTypeFactoryWithNoParams;
+ DateTime2: ISqlTypeFactoryWithScale;
+ DateTimeOffset: ISqlTypeFactoryWithScale;
+ SmallDateTime: ISqlTypeFactoryWithNoParams;
+ Time: ISqlTypeFactoryWithScale;
+ UniqueIdentifier: ISqlTypeFactoryWithNoParams;
+ SmallMoney: ISqlTypeFactoryWithNoParams;
+ Money: ISqlTypeFactoryWithNoParams;
+ Binary: ISqlTypeFactoryWithNoParams;
+ VarBinary: ISqlTypeFactoryWithLength;
+ Image: ISqlTypeFactoryWithNoParams;
+ Xml: ISqlTypeFactoryWithNoParams;
+ Char: ISqlTypeFactoryWithLength;
+ NChar: ISqlTypeFactoryWithLength;
+ NText: ISqlTypeFactoryWithNoParams;
+ TVP: ISqlTypeFactoryWithTvpType;
+ UDT: ISqlTypeFactoryWithNoParams;
+ Geography: ISqlTypeFactoryWithNoParams;
+ Geometry: ISqlTypeFactoryWithNoParams;
};
export declare var MAX: number;
@@ -100,8 +105,19 @@ interface IMap extends Array<{ js: any, sql: any }> {
export declare var map: IMap;
export declare var DRIVERS: string[];
+export interface IColumnMetadata {
+ [name: string]: {
+ index: number;
+ name: string;
+ length: number;
+ type: ISqlType;
+ udt?: any;
+ }
+}
+export interface IRecordSet extends Array {
+ columns: IColumnMetadata;
+}
-type recordSet = any;
type IIsolationLevel = number;
export declare var ISOLATION_LEVEL: {
@@ -204,22 +220,23 @@ export declare class Request extends events.EventEmitter {
public constructor(connection?: Connection);
public constructor(transaction: Transaction);
public constructor(preparedStatement: PreparedStatement);
- public execute(procedure: string): Promise;
- public execute(procedure: string, callback: (err?: any, recordsets?: Entity[], returnValue?: any, rowsAffected?: number) => 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: NodeJS.WritableStream): void;
- public query(command: string): Promise;
- public query(command: string): Promise;
- public query(command: string, callback: (err?: any, recordset?: any, rowsAffected?: number) => void): void;
- public query(command: string, callback: (err?: any, recordset?: Entity[]) => void): void;
- public batch(batch: string): Promise;
- public batch(batch: string): Promise;
- public batch(batch: string, callback: (err?: any, recordset?: any) => void): void;
- public batch(batch: string, callback: (err?: any, recordset?: Entity[]) => void): void;
- public bulk(table: Table): Promise;
- public bulk(table: Table, callback: (err: any, rowCount: any) => void): void;
+ public execute(procedure: string): Promise>;
+ public execute(procedure: string): Promise>;
+ public execute(procedure: string, callback: (err?: any, recordsets?: IRecordSet, returnValue?: any, rowsAffected?: number) => void): void;
+ public input(name: string, value: any): Request;
+ public input(name: string, type: any, value: any): Request;
+ public output(name: string, type: any, value?: any): Request;
+ public pipe(stream: NodeJS.WritableStream): NodeJS.WritableStream;
+ public query(command: string): Promise>;
+ public query(command: string): Promise>;
+ public query(command: string, callback: (err?: Error, recordset?: IRecordSet, rowsAffected?: number) => void): void;
+ public query(command: string, callback: (err?: Error, recordset?: IRecordSet) => void): void;
+ public batch(batch: string): Promise>;
+ public batch(batch: string): Promise>;
+ public batch(batch: string, callback: (err?: Error, recordset?: IRecordSet) => void): void;
+ public batch(batch: string, callback: (err?: any, recordset?: IRecordSet) => void): void;
+ public bulk(table: Table): Promise;
+ public bulk(table: Table, callback: (err: Error, rowCount: any) => void): void;
public cancel(): void;
}
@@ -258,16 +275,14 @@ export declare class PreparedStatement extends events.EventEmitter {
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 input(name: string, type: ISqlType): PreparedStatement;
+ public output(name: string, type: ISqlType): PreparedStatement;
public prepare(statement?: string): Promise;
- public prepare(statement?: string, callback?: (err?: any) => void): void;
- public execute(values: Object): Promise;
- public execute(values: Object): Promise;
- public execute(values: Object, callback: (err: any, recordSet: recordSet, rowsAffected: number) => void): void;
- public execute(values: Object, callback: (err: any, recordSet: Entity[]) => void): void;
+ public prepare(statement?: string, callback?: (err?: Error) => void): PreparedStatement;
+ public execute(values: Object): Promise;
+ public execute(values: Object, callback: (err?: Error) => void): Request;
public unprepare(): Promise;
- public unprepare(callback: (err?: any) => void): void;
+ public unprepare(callback: (err?: Error) => void): PreparedStatement;
}
export declare class PreparedStatementError implements Error {