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