mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
Improve types.
This commit is contained in:
Vendored
+27
-11
@@ -1,4 +1,4 @@
|
||||
// Type definitions for mssql 4.0.1
|
||||
// Type definitions for mssql 4.0.2
|
||||
// Project: https://www.npmjs.com/package/mssql
|
||||
// Definitions by: COLSA Corporation <http://www.colsa.com/>, Ben Farr <https://github.com/jaminfarr>, Vitor Buzinaro <https://github.com/buzinas>, Matt Richardson <https://github.com/mrrichar/>, Jørgen Elgaard Larsen <https://github.com/elhaard/>, Peter Keuter <https://github.com/pkeuter/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
@@ -57,6 +57,7 @@ export declare var TVP: ISqlTypeFactoryWithTvpType;
|
||||
export declare var UDT: ISqlTypeFactoryWithNoParams;
|
||||
export declare var Geography: ISqlTypeFactoryWithNoParams;
|
||||
export declare var Geometry: ISqlTypeFactoryWithNoParams;
|
||||
export declare var Variant: ISqlTypeFactoryWithNoParams;
|
||||
|
||||
export declare var TYPES: {
|
||||
VarChar: ISqlTypeFactoryWithLength;
|
||||
@@ -91,6 +92,7 @@ export declare var TYPES: {
|
||||
UDT: ISqlTypeFactoryWithNoParams;
|
||||
Geography: ISqlTypeFactoryWithNoParams;
|
||||
Geometry: ISqlTypeFactoryWithNoParams;
|
||||
Variant: ISqlTypeFactoryWithNoParams;
|
||||
};
|
||||
|
||||
export declare var MAX: number;
|
||||
@@ -109,7 +111,7 @@ export interface IColumnMetadata {
|
||||
index: number;
|
||||
name: string;
|
||||
length: number;
|
||||
type: ISqlType;
|
||||
type: (() => ISqlType) | ISqlType;
|
||||
udt?: any;
|
||||
}
|
||||
}
|
||||
@@ -166,6 +168,7 @@ export interface config {
|
||||
connectionTimeout?: number;
|
||||
requestTimeout?: number;
|
||||
stream?: boolean;
|
||||
parseJSON?: boolean;
|
||||
options?: IOptions;
|
||||
pool?: IPool;
|
||||
}
|
||||
@@ -191,25 +194,38 @@ export declare class ConnectionError implements Error {
|
||||
public code: string;
|
||||
}
|
||||
|
||||
declare class columns {
|
||||
public add(name: string, type: any, options: any): void;
|
||||
export interface IColumnOptions {
|
||||
nullable?: boolean;
|
||||
primary?: boolean;
|
||||
}
|
||||
|
||||
export interface IColumn extends ISqlType {
|
||||
name: string;
|
||||
nullable: boolean;
|
||||
primary: boolean;
|
||||
}
|
||||
|
||||
declare class columns {
|
||||
public add(name: string, type: (() => ISqlType) | ISqlType, options?: IColumnOptions): number;
|
||||
}
|
||||
|
||||
type IRow = (string | number | boolean | Date | Buffer)[];
|
||||
|
||||
declare class rows {
|
||||
public add(...row: any[]): void;
|
||||
public add(...row: IRow): number;
|
||||
}
|
||||
|
||||
export declare class Table {
|
||||
public create: boolean;
|
||||
public columns: columns;
|
||||
public rows: rows;
|
||||
public constructor(tableName: string);
|
||||
public constructor(tableName?: string);
|
||||
}
|
||||
|
||||
interface IRequestParameters {
|
||||
[name: string]: {
|
||||
name: string;
|
||||
type: any;
|
||||
type: (() => ISqlType) | ISqlType;
|
||||
io: number;
|
||||
value: any;
|
||||
length: number;
|
||||
@@ -233,8 +249,8 @@ export declare class Request extends events.EventEmitter {
|
||||
public execute<Entity>(procedure: string): Promise<IProcedureResult<Entity>>;
|
||||
public execute<Entity>(procedure: string, callback: (err?: any, recordsets?: IProcedureResult<Entity>, returnValue?: any) => 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 input(name: string, type: (() => ISqlType) | ISqlType, value: any): Request;
|
||||
public output(name: string, type: (() => ISqlType) | ISqlType, value?: any): Request;
|
||||
public pipe(stream: NodeJS.WritableStream): NodeJS.WritableStream;
|
||||
public query(command: string): Promise<IResult<any>>;
|
||||
public query<Entity>(command: string): Promise<IResult<Entity>>;
|
||||
@@ -280,8 +296,8 @@ export declare class PreparedStatement extends events.EventEmitter {
|
||||
public parameters: IRequestParameters;
|
||||
public stream: any;
|
||||
public constructor(connection?: ConnectionPool);
|
||||
public input(name: string, type: ISqlType): PreparedStatement;
|
||||
public output(name: string, type: ISqlType): PreparedStatement;
|
||||
public input(name: string, type: (() => ISqlType) | ISqlType): PreparedStatement;
|
||||
public output(name: string, type: (() => ISqlType) | ISqlType): PreparedStatement;
|
||||
public prepare(statement?: string): Promise<void>;
|
||||
public prepare(statement?: string, callback?: (err?: Error) => void): PreparedStatement;
|
||||
public execute(values: Object): Promise<void>;
|
||||
|
||||
+10
-11
@@ -1,6 +1,6 @@
|
||||
import sql = require('mssql');
|
||||
import * as sql from 'mssql';
|
||||
|
||||
interface Entity{
|
||||
interface Entity {
|
||||
value: number;
|
||||
}
|
||||
|
||||
@@ -26,15 +26,14 @@ var connection: sql.ConnectionPool = new sql.ConnectionPool(config, function (er
|
||||
console.warn("Issue with connecting to SQL Server!");
|
||||
}
|
||||
else {
|
||||
connection.query`SELECT ${1} as value`.then(res => { });
|
||||
connection.query`SELECT ${1} as value`.then(res => { });
|
||||
var requestQuery = new sql.Request(connection);
|
||||
|
||||
var getArticlesQuery = "SELECT * FROM TABLE";
|
||||
|
||||
requestQuery.query(getArticlesQuery, function (err, result) {
|
||||
if (err) {
|
||||
console.error('Error happened calling Query: ' + err.name + " " + err.message);
|
||||
|
||||
console.error(`Error happened calling Query: ${err.name} ${err.message}`);
|
||||
}
|
||||
// checking to see if the articles returned as at least one.
|
||||
else if (result.recordset.length > 0) {
|
||||
@@ -45,7 +44,7 @@ var connection: sql.ConnectionPool = new sql.ConnectionPool(config, function (er
|
||||
|
||||
requestQuery.query<Entity>(getArticlesQuery, function (err, result) {
|
||||
if (err) {
|
||||
console.error('Error happened calling Query: ' + err.name + " " + err.message);
|
||||
console.error(`Error happened calling Query: ${err.name} ${err.message}`);
|
||||
|
||||
}
|
||||
// checking to see if the articles returned as at least one.
|
||||
@@ -63,7 +62,7 @@ var connection: sql.ConnectionPool = new sql.ConnectionPool(config, function (er
|
||||
|
||||
requestStoredProcedure.execute('StoredProcedureName', function (err, recordsets, returnValue) {
|
||||
if (err != null) {
|
||||
console.error('Error happened calling Query: ' + err.name + " " + err.message);
|
||||
console.error(`Error happened calling Query: ${err.name} ${err.message}`);
|
||||
}
|
||||
else {
|
||||
console.info(returnValue);
|
||||
@@ -72,7 +71,7 @@ var connection: sql.ConnectionPool = new sql.ConnectionPool(config, function (er
|
||||
|
||||
requestStoredProcedure.execute<Entity>('StoredProcedureName', function (err, recordsets, returnValue) {
|
||||
if (err != null) {
|
||||
console.error('Error happened calling Query: ' + err.name + " " + err.message);
|
||||
console.error(`Error happened calling Query: ${err.name} ${err.message}`);
|
||||
}
|
||||
else {
|
||||
console.info(returnValue);
|
||||
@@ -97,7 +96,7 @@ var connection: sql.ConnectionPool = new sql.ConnectionPool(config, function (er
|
||||
|
||||
requestStoredProcedure.execute('StoredProcedureName', function (err, recordsets, returnValue) {
|
||||
if (err != null) {
|
||||
console.error('Error happened calling Query: ' + err.name + " " + err.message);
|
||||
console.error(`Error happened calling Query: ${err.name} ${err.message}`);
|
||||
}
|
||||
else {
|
||||
console.info(requestStoredProcedureWithOutput.parameters['output'].value);
|
||||
@@ -106,7 +105,7 @@ var connection: sql.ConnectionPool = new sql.ConnectionPool(config, function (er
|
||||
|
||||
requestStoredProcedure.execute<Entity>('StoredProcedureName', function (err, recordsets, returnValue) {
|
||||
if (err != null) {
|
||||
console.error('Error happened calling Query: ' + err.name + " " + err.message);
|
||||
console.error(`Error happened calling Query: ${err.name} ${err.message}`);
|
||||
}
|
||||
else {
|
||||
console.info(requestStoredProcedureWithOutput.parameters['output'].value);
|
||||
@@ -150,7 +149,7 @@ function test_promise_returns() {
|
||||
request.batch<Entity>('create procedure #temporary as select * from table;select 1 as value').then((recordset) => { });
|
||||
request.bulk(new sql.Table("table_name")).then(() => { });
|
||||
request.query('SELECT 1').then((recordset) => { });
|
||||
request.query<Entity>('SELECT 1 as value').then(res => { });
|
||||
request.query<Entity>('SELECT 1 as value').then(res => { });
|
||||
request.execute('procedure_name').then((recordset) => { });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user