1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import events = require('events');
|
18 | import { Readable, ReadableOptions } from 'stream';
|
19 | import tds = require('tedious');
|
20 | import { Pool } from 'tarn';
|
21 | import { CallbackOrPromise, PoolOptions } from 'tarn/dist/Pool';
|
22 | export interface ISqlType {
|
23 | type: ISqlTypeFactory;
|
24 | }
|
25 | export interface ISqlTypeWithNoParams extends ISqlType { type: ISqlTypeFactoryWithNoParams }
|
26 | export interface ISqlTypeWithLength extends ISqlType { type: ISqlTypeFactoryWithLength; length: number }
|
27 | export interface ISqlTypeWithScale extends ISqlType { type: ISqlTypeFactoryWithScale; scale: number }
|
28 | export interface ISqlTypeWithPrecisionScale extends ISqlType { type: ISqlTypeFactoryWithPrecisionScale; precision: number, scale: number }
|
29 | export interface ISqlTypeWithTvpType extends ISqlType { type: ISqlTypeFactoryWithTvpType; tvpType: any }
|
30 |
|
31 | export interface ISqlTypeFactory {
|
32 | }
|
33 | export interface ISqlTypeFactoryWithNoParams extends ISqlTypeFactory { (): ISqlTypeWithNoParams; }
|
34 | export interface ISqlTypeFactoryWithLength extends ISqlTypeFactory { (length?: number): ISqlTypeWithLength }
|
35 | export interface ISqlTypeFactoryWithScale extends ISqlTypeFactory { (scale?: number): ISqlTypeWithScale }
|
36 | export interface ISqlTypeFactoryWithPrecisionScale extends ISqlTypeFactory { (precision?: number, scale?: number): ISqlTypeWithPrecisionScale; }
|
37 | export interface ISqlTypeFactoryWithTvpType extends ISqlTypeFactory { (tvpType?: any): ISqlTypeWithTvpType }
|
38 |
|
39 |
|
40 | export declare var VarChar: ISqlTypeFactoryWithLength;
|
41 | export declare var NVarChar: ISqlTypeFactoryWithLength;
|
42 | export declare var Text: ISqlTypeFactoryWithNoParams;
|
43 | export declare var Int: ISqlTypeFactoryWithNoParams;
|
44 | export declare var BigInt: ISqlTypeFactoryWithNoParams;
|
45 | export declare var TinyInt: ISqlTypeFactoryWithNoParams;
|
46 | export declare var SmallInt: ISqlTypeFactoryWithNoParams;
|
47 | export declare var Bit: ISqlTypeFactoryWithNoParams;
|
48 | export declare var Float: ISqlTypeFactoryWithNoParams;
|
49 | export declare var Numeric: ISqlTypeFactoryWithPrecisionScale;
|
50 | export declare var Decimal: ISqlTypeFactoryWithPrecisionScale;
|
51 | export declare var Real: ISqlTypeFactoryWithNoParams;
|
52 | export declare var Date: ISqlTypeFactoryWithNoParams;
|
53 | export declare var DateTime: ISqlTypeFactoryWithNoParams;
|
54 | export declare var DateTime2: ISqlTypeFactoryWithScale;
|
55 | export declare var DateTimeOffset: ISqlTypeFactoryWithScale;
|
56 | export declare var SmallDateTime: ISqlTypeFactoryWithNoParams;
|
57 | export declare var Time: ISqlTypeFactoryWithScale;
|
58 | export declare var UniqueIdentifier: ISqlTypeFactoryWithNoParams;
|
59 | export declare var SmallMoney: ISqlTypeFactoryWithNoParams;
|
60 | export declare var Money: ISqlTypeFactoryWithNoParams;
|
61 | export declare var Binary: ISqlTypeFactoryWithNoParams;
|
62 | export declare var VarBinary: ISqlTypeFactoryWithLength;
|
63 | export declare var Image: ISqlTypeFactoryWithNoParams;
|
64 | export declare var Xml: ISqlTypeFactoryWithNoParams;
|
65 | export declare var Char: ISqlTypeFactoryWithLength;
|
66 | export declare var NChar: ISqlTypeFactoryWithLength;
|
67 | export declare var NText: ISqlTypeFactoryWithNoParams;
|
68 | export declare var TVP: ISqlTypeFactoryWithTvpType;
|
69 | export declare var UDT: ISqlTypeFactoryWithNoParams;
|
70 | export declare var Geography: ISqlTypeFactoryWithNoParams;
|
71 | export declare var Geometry: ISqlTypeFactoryWithNoParams;
|
72 | export declare var Variant: ISqlTypeFactoryWithNoParams;
|
73 |
|
74 | export type Connection = tds.Connection;
|
75 |
|
76 | export declare var TYPES: {
|
77 | VarChar: ISqlTypeFactoryWithLength;
|
78 | NVarChar: ISqlTypeFactoryWithLength;
|
79 | Text: ISqlTypeFactoryWithNoParams;
|
80 | Int: ISqlTypeFactoryWithNoParams;
|
81 | BigInt: ISqlTypeFactoryWithNoParams;
|
82 | TinyInt: ISqlTypeFactoryWithNoParams;
|
83 | SmallInt: ISqlTypeFactoryWithNoParams;
|
84 | Bit: ISqlTypeFactoryWithNoParams;
|
85 | Float: ISqlTypeFactoryWithNoParams;
|
86 | Numeric: ISqlTypeFactoryWithPrecisionScale;
|
87 | Decimal: ISqlTypeFactoryWithPrecisionScale;
|
88 | Real: ISqlTypeFactoryWithNoParams;
|
89 | Date: ISqlTypeFactoryWithNoParams;
|
90 | DateTime: ISqlTypeFactoryWithNoParams;
|
91 | DateTime2: ISqlTypeFactoryWithScale;
|
92 | DateTimeOffset: ISqlTypeFactoryWithScale;
|
93 | SmallDateTime: ISqlTypeFactoryWithNoParams;
|
94 | Time: ISqlTypeFactoryWithScale;
|
95 | UniqueIdentifier: ISqlTypeFactoryWithNoParams;
|
96 | SmallMoney: ISqlTypeFactoryWithNoParams;
|
97 | Money: ISqlTypeFactoryWithNoParams;
|
98 | Binary: ISqlTypeFactoryWithNoParams;
|
99 | VarBinary: ISqlTypeFactoryWithLength;
|
100 | Image: ISqlTypeFactoryWithNoParams;
|
101 | Xml: ISqlTypeFactoryWithNoParams;
|
102 | Char: ISqlTypeFactoryWithLength;
|
103 | NChar: ISqlTypeFactoryWithLength;
|
104 | NText: ISqlTypeFactoryWithNoParams;
|
105 | TVP: ISqlTypeFactoryWithTvpType;
|
106 | UDT: ISqlTypeFactoryWithNoParams;
|
107 | Geography: ISqlTypeFactoryWithNoParams;
|
108 | Geometry: ISqlTypeFactoryWithNoParams;
|
109 | Variant: ISqlTypeFactoryWithNoParams;
|
110 | };
|
111 |
|
112 | export declare var MAX: number;
|
113 | export declare var fix: boolean;
|
114 | export declare var Promise: any;
|
115 |
|
116 | interface IMap extends Array<{ js: any, sql: any }> {
|
117 | register(jstype: any, sql: any): void;
|
118 | }
|
119 |
|
120 | export declare var map: IMap;
|
121 |
|
122 | export declare var DRIVERS: string[];
|
123 | export interface IColumnMetadata {
|
124 | [name: string]: {
|
125 | index: number;
|
126 | name: string;
|
127 | length: number;
|
128 | type: (() => ISqlType) | ISqlType;
|
129 | udt?: any;
|
130 | scale?: number | undefined;
|
131 | precision?: number | undefined;
|
132 | nullable: boolean;
|
133 | caseSensitive: boolean;
|
134 | identity: boolean;
|
135 | readOnly: boolean;
|
136 | }
|
137 | }
|
138 | export interface IResult<T> {
|
139 | recordsets: T extends Array<any> ? { [P in keyof T]: IRecordSet<T[P]> } : IRecordSet<T>[];
|
140 | recordset: IRecordSet<T extends Array<any> ? T[0] : T>;
|
141 | rowsAffected: number[],
|
142 | output: { [key: string]: any };
|
143 | }
|
144 |
|
145 | export interface IBulkResult {
|
146 | rowsAffected: number;
|
147 | }
|
148 |
|
149 | export interface IProcedureResult<T> extends IResult<T> {
|
150 | returnValue: any;
|
151 | }
|
152 | export interface IRecordSet<T> extends Array<T> {
|
153 | columns: IColumnMetadata;
|
154 | toTable(name?: string): Table;
|
155 | }
|
156 |
|
157 | type IIsolationLevel = number;
|
158 |
|
159 | export declare var ISOLATION_LEVEL: {
|
160 | READ_UNCOMMITTED: IIsolationLevel
|
161 | READ_COMMITTED: IIsolationLevel
|
162 | REPEATABLE_READ: IIsolationLevel
|
163 | SERIALIZABLE: IIsolationLevel
|
164 | SNAPSHOT: IIsolationLevel
|
165 | }
|
166 |
|
167 | export interface IOptions extends Omit<tds.ConnectionOptions, 'useColumnNames'> {
|
168 | beforeConnect?: void | undefined;
|
169 | connectionString?: string | undefined;
|
170 | trustedConnection?: boolean | undefined;
|
171 | }
|
172 |
|
173 | export declare var pool: ConnectionPool;
|
174 |
|
175 | export interface PoolOpts<T> extends Omit<PoolOptions<T>, 'create' | 'destroy' | 'min' | 'max'> {
|
176 | create?: CallbackOrPromise<T> | undefined;
|
177 | destroy?: ((resource: T) => any) | undefined;
|
178 | min?: number | undefined;
|
179 | max?: number | undefined;
|
180 | }
|
181 |
|
182 | export interface config {
|
183 | driver?: string | undefined;
|
184 | user?: string | undefined;
|
185 | password?: string | undefined;
|
186 | server: string;
|
187 | port?: number | undefined;
|
188 | domain?: string | undefined;
|
189 | database?: string | undefined;
|
190 | connectionTimeout?: number | undefined;
|
191 | requestTimeout?: number | undefined;
|
192 | stream?: boolean | undefined;
|
193 | parseJSON?: boolean | undefined;
|
194 | options?: IOptions | undefined;
|
195 | pool?: PoolOpts<Connection> | undefined;
|
196 | arrayRowMode?: boolean | undefined;
|
197 | authentication?: tds.ConnectionAuthentication | undefined;
|
198 | /**
|
199 | * Invoked before opening the connection. The parameter conn is the configured
|
200 | * tedious Connection. It can be used for attaching event handlers.
|
201 | */
|
202 | beforeConnect?: ((conn: Connection) => void) | undefined
|
203 | }
|
204 |
|
205 | export declare class MSSQLError extends Error {
|
206 | constructor(message: Error | string, code?: string);
|
207 | public code: string;
|
208 | public name: string;
|
209 | public originalError?: Error | undefined;
|
210 | }
|
211 |
|
212 | export declare class ConnectionPool extends events.EventEmitter {
|
213 | public readonly connected: boolean;
|
214 | public readonly connecting: boolean;
|
215 | public readonly healthy: boolean;
|
216 | public readonly driver: string;
|
217 | public readonly size: number;
|
218 | public readonly available: number;
|
219 | public readonly pending: number;
|
220 | public readonly borrowed: number;
|
221 | public readonly pool: Pool<Connection>;
|
222 | public static parseConnectionString(connectionString: string): config & { options: IOptions, pool: Partial<PoolOpts<Connection>> };
|
223 | public constructor(config: config, callback?: (err?: any) => void);
|
224 | public constructor(connectionString: string, callback?: (err?: any) => void);
|
225 | public query(command: string): Promise<IResult<any>>;
|
226 | public query(strings: TemplateStringsArray, ...interpolations: any[]): Promise<IResult<any>>;
|
227 | public query<Entity>(command: string): Promise<IResult<Entity>>;
|
228 | public query<Entity>(strings: TemplateStringsArray, ...interpolations: any[]): Promise<IResult<Entity>>;
|
229 | public query<Entity>(command: string, callback: (err?: Error, recordset?: IResult<Entity>) => void): void;
|
230 | public batch(batch: string): Promise<IResult<any>>;
|
231 | public batch(strings: TemplateStringsArray, ...interpolations: any[]): Promise<IResult<any>>;
|
232 | public batch(batch: string, callback: (err?: Error, recordset?: IResult<any>) => void): void;
|
233 | public batch<Entity>(batch: string): Promise<IResult<Entity>>;
|
234 | public batch<Entity>(strings: TemplateStringsArray, ...interpolations: any[]): Promise<IResult<Entity>>;
|
235 | public connect(): Promise<ConnectionPool>;
|
236 | public connect(callback: (err: any) => void): void;
|
237 | public close(): Promise<void>;
|
238 | public close(callback: (err: any) => void): void;
|
239 | public request(): Request;
|
240 | public transaction(): Transaction;
|
241 | }
|
242 |
|
243 | export declare class ConnectionError extends MSSQLError {}
|
244 |
|
245 | export interface IColumnOptions {
|
246 | nullable?: boolean | undefined;
|
247 | primary?: boolean | undefined;
|
248 | identity?: boolean | undefined;
|
249 | readOnly?: boolean | undefined;
|
250 | length?: number | undefined
|
251 | }
|
252 |
|
253 | export interface IColumn extends ISqlType {
|
254 | name: string;
|
255 | nullable: boolean;
|
256 | primary: boolean;
|
257 | }
|
258 |
|
259 | declare class columns extends Array<IColumn> {
|
260 | public add(name: string, type: (() => ISqlType) | ISqlType, options?: IColumnOptions): number;
|
261 | }
|
262 |
|
263 | type IRow = (string | number | boolean | Date | Buffer | undefined | null)[];
|
264 |
|
265 | declare class rows extends Array<IRow> {
|
266 | public add(...row: IRow): number;
|
267 | }
|
268 |
|
269 | export declare class Table {
|
270 | public create: boolean;
|
271 | public columns: columns;
|
272 | public rows: rows;
|
273 | public constructor(tableName?: string);
|
274 | public schema?: string | undefined;
|
275 | public database?: string | undefined;
|
276 | public name?: string | undefined;
|
277 | public path?: string | undefined;
|
278 | public temporary?: boolean | undefined;
|
279 | }
|
280 |
|
281 | interface IRequestParameters {
|
282 | [name: string]: {
|
283 | name: string;
|
284 | type: (() => ISqlType) | ISqlType;
|
285 | io: number;
|
286 | value: any;
|
287 | length: number;
|
288 | scale: number;
|
289 | precision: number;
|
290 | tvpType: any;
|
291 | }
|
292 | }
|
293 |
|
294 | /**
|
295 | * Options object to be passed through to driver (currently tedious only)
|
296 | */
|
297 | export interface IBulkOptions {
|
298 | /** Honors constraints during bulk load, using T-SQL CHECK_CONSTRAINTS. (default: false) */
|
299 | checkConstraints?: boolean | undefined;
|
300 | /** Honors insert triggers during bulk load, using the T-SQL FIRE_TRIGGERS. (default: false) */
|
301 | fireTriggers?: boolean | undefined;
|
302 | /** Honors null value passed, ignores the default values set on table, using T-SQL KEEP_NULLS. (default: false) */
|
303 | keepNulls?: boolean | undefined;
|
304 | /** Places a bulk update(BU) lock on table while performing bulk load, using T-SQL TABLOCK. (default: false) */
|
305 | tableLock?: boolean | undefined;
|
306 | }
|
307 |
|
308 | export declare class Request extends events.EventEmitter {
|
309 | public transaction: Transaction;
|
310 | public pstatement: PreparedStatement;
|
311 | public parameters: IRequestParameters;
|
312 | public verbose: boolean;
|
313 | public canceled: boolean;
|
314 | public multiple: boolean;
|
315 | public stream: any;
|
316 | public constructor(connection?: ConnectionPool);
|
317 | public constructor(transaction: Transaction);
|
318 | public constructor(preparedStatement: PreparedStatement);
|
319 | public execute(procedure: string): Promise<IProcedureResult<any>>;
|
320 | public execute<Entity>(procedure: string): Promise<IProcedureResult<Entity>>;
|
321 | public execute<Entity>(procedure: string, callback: (err?: any, recordsets?: IProcedureResult<Entity>, returnValue?: any) => void): void;
|
322 | public input(name: string, value: any): Request;
|
323 | public input(name: string, type: (() => ISqlType) | ISqlType, value: any): Request;
|
324 | public replaceInput(name: string, value: any): Request;
|
325 | public replaceInput(name: string, type: (() => ISqlType) | ISqlType, value: any): Request;
|
326 | public output(name: string, type: (() => ISqlType) | ISqlType, value?: any): Request;
|
327 | public pipe(stream: NodeJS.WritableStream): NodeJS.WritableStream;
|
328 | public query(command: string): Promise<IResult<any>>;
|
329 | public query(command: TemplateStringsArray, ...interpolations: any[]): Promise<IResult<any>>;
|
330 | public query<Entity>(command: string): Promise<IResult<Entity>>;
|
331 | public query<Entity>(command: TemplateStringsArray, ...interpolations: any[]): Promise<IResult<Entity>>;
|
332 | public query<Entity>(command: string, callback: (err?: Error, recordset?: IResult<Entity>) => void): void;
|
333 | public batch(batch: string): Promise<IResult<any>>;
|
334 | public batch(strings: TemplateStringsArray, ...interpolations: any[]): Promise<IResult<any>>;
|
335 | public batch(batch: string, callback: (err?: Error, recordset?: IResult<any>) => void): void;
|
336 | public batch<Entity>(batch: string): Promise<IResult<Entity>>;
|
337 | public batch<Entity>(strings: TemplateStringsArray, ...interpolations: any[]): Promise<IResult<Entity>>;
|
338 | public batch<Entity>(batch: string, callback: (err?: any, recordset?: IResult<Entity>) => void): void;
|
339 | public bulk(table: Table): Promise<IBulkResult>;
|
340 | public bulk(table: Table, options: IBulkOptions): Promise<IBulkResult>;
|
341 | public bulk(table: Table, callback: (err: Error, result: IBulkResult) => void): void;
|
342 | public bulk(table: Table, options: IBulkOptions, callback: (err: Error, result: IBulkResult) => void): void;
|
343 | public cancel(): void;
|
344 | public pause(): boolean;
|
345 | public resume(): boolean;
|
346 | public toReadableStream(streamOptions?: ReadableOptions): Readable;
|
347 | }
|
348 |
|
349 | export declare class RequestError extends MSSQLError {
|
350 | public number?: number | undefined;
|
351 | public lineNumber?: number | undefined;
|
352 | public state?: string | undefined;
|
353 | public class?: string | undefined;
|
354 | public serverName?: string | undefined;
|
355 | public procName?: string | undefined;
|
356 | }
|
357 |
|
358 | export declare class Transaction extends events.EventEmitter {
|
359 | public isolationLevel: IIsolationLevel;
|
360 | public constructor(connection?: ConnectionPool);
|
361 | /**
|
362 | * Begin a transaction.
|
363 | * @param [isolationLevel] - Controls the locking and row versioning behavior of TSQL statements issued by a connection.
|
364 | * @param [callback] A callback which is called after transaction has began, or an error has occurred. If omited, method returns Promise.
|
365 | */
|
366 | public begin(isolationLevel?: IIsolationLevel): Promise<Transaction>;
|
367 | public begin(isolationLevel?: IIsolationLevel, callback?: (err?: ConnectionError | TransactionError) => void): Transaction;
|
368 | public commit(): Promise<void>;
|
369 | public commit(callback: (err?: any) => void): void;
|
370 | public rollback(): Promise<void>;
|
371 | public rollback(callback: (err?: any) => void): void;
|
372 | public request(): Request;
|
373 | }
|
374 |
|
375 | export declare class TransactionError extends MSSQLError {}
|
376 |
|
377 | export declare class PreparedStatement extends events.EventEmitter {
|
378 | public transaction: Transaction;
|
379 | public prepared: boolean;
|
380 | public statement: string;
|
381 | public parameters: IRequestParameters;
|
382 | public stream: any;
|
383 | public constructor(connection?: ConnectionPool);
|
384 | public constructor(transaction: Transaction);
|
385 | public input(name: string, type: (() => ISqlType) | ISqlType): PreparedStatement;
|
386 | public output(name: string, type: (() => ISqlType) | ISqlType): PreparedStatement;
|
387 | public prepare(statement?: string): Promise<void>;
|
388 | public prepare(statement?: string, callback?: (err?: Error) => void): PreparedStatement;
|
389 | public execute(values: Object): Promise<IProcedureResult<any>>;
|
390 | public execute<Entity>(values: Object): Promise<IProcedureResult<Entity>>;
|
391 | public execute(values: Object, callback: (err?: Error, result?: IProcedureResult<any>) => void): Request;
|
392 | public execute<Entity>(values: Object, callback: (err?: Error, result?: IProcedureResult<Entity>) => void): Request;
|
393 | public unprepare(): Promise<void>;
|
394 | public unprepare(callback: (err?: Error) => void): PreparedStatement;
|
395 | }
|
396 |
|
397 | export declare class PreparedStatementError extends MSSQLError {}
|
398 |
|
399 | /**
|
400 | * Open global connection pool.
|
401 | * @param config Connection configuration object or connection string
|
402 | */
|
403 | export declare function connect(config: config | string): Promise<ConnectionPool>;
|
404 |
|
405 | /**
|
406 | * Open global connection pool.
|
407 | * @param config Connection configuration object or connection string.
|
408 | * @param callback A callback which is called after connection has established, or an error has occurred
|
409 | */
|
410 | export declare function connect(config: config | string, callback?: (err?: Error) => void): void;
|
411 |
|
412 |
|
413 | export declare function query(command: string): Promise<IResult<any>>;
|
414 | export declare function query(command: TemplateStringsArray, ...interpolations: any[]): Promise<IResult<any>>;
|
415 | export declare function query<Entity>(command: string): Promise<IResult<Entity>>;
|
416 | export declare function query<Entity>(command: TemplateStringsArray, ...interpolations: any[]): Promise<IResult<Entity>>;
|
417 | export declare function query<Entity>(command: string, callback: (err?: Error, recordset?: IResult<Entity>) => void): void;
|
418 |
|
\ | No newline at end of file |