UNPKG

12 kBTypeScriptView Raw
1/// <reference types="node" />
2import { type CryptoMetadata } from './always-encrypted/types';
3import { type InternalConnectionOptions } from './connection';
4import { Collation } from './collation';
5export interface Parameter {
6 type: DataType;
7 name: string;
8 value: unknown;
9 output: boolean;
10 length?: number | undefined;
11 precision?: number | undefined;
12 scale?: number | undefined;
13 nullable?: boolean | undefined;
14 forceEncrypt?: boolean | undefined;
15 cryptoMetadata?: CryptoMetadata | undefined;
16 encryptedVal?: Buffer | undefined;
17}
18export interface ParameterData<T = any> {
19 length?: number | undefined;
20 scale?: number | undefined;
21 precision?: number | undefined;
22 collation?: Collation | undefined;
23 value: T;
24}
25export interface DataType {
26 id: number;
27 type: string;
28 name: string;
29 declaration(parameter: Parameter): string;
30 generateTypeInfo(parameter: ParameterData, options: InternalConnectionOptions): Buffer;
31 generateParameterLength(parameter: ParameterData, options: InternalConnectionOptions): Buffer;
32 generateParameterData(parameter: ParameterData, options: InternalConnectionOptions): Generator<Buffer, void>;
33 validate(value: any, collation: Collation | undefined, options?: InternalConnectionOptions): any;
34 hasTableName?: boolean;
35 resolveLength?: (parameter: Parameter) => number;
36 resolvePrecision?: (parameter: Parameter) => number;
37 resolveScale?: (parameter: Parameter) => number;
38}
39export declare const TYPE: {
40 [x: number]: DataType;
41};
42/**
43 * <table>
44 * <thead>
45 * <tr>
46 * <th>Type</th>
47 * <th>Constant</th>
48 * <th>JavaScript</th>
49 * <th>Result set</th>
50 * <th>Parameter</th>
51 * </tr>
52 * </thead>
53 *
54 * <tbody>
55 * <tr class="group-heading">
56 * <th colspan="5">Exact numerics</th>
57 * </tr>
58 * <tr>
59 * <td><code>bit</code></td>
60 * <td><code>[[TYPES.Bit]]</code></td>
61 * <td><code>boolean</code></td>
62 * <td>✓</td>
63 * <td>✓</td>
64 * </tr>
65 * <tr>
66 * <td><code>tinyint</code></td>
67 * <td><code>[[TYPES.TinyInt]]</code></td>
68 * <td><code>number</code></td>
69 * <td>✓</td>
70 * <td>✓</td>
71 * </tr>
72 * <tr>
73 * <td><code>smallint</code></td>
74 * <td><code>[[TYPES.SmallInt]]</code></td>
75 * <td><code>number</code></td>
76 * <td>✓</td>
77 * <td>✓</td>
78 * </tr>
79 * <tr>
80 * <td><code>int</code></td>
81 * <td><code>[[TYPES.Int]]</code></td>
82 * <td><code>number</code></td>
83 * <td>✓</td>
84 * <td>✓</td>
85 * </tr>
86 * <tr>
87 * <td><code>bigint</code><sup>1</sup></td>
88 * <td><code>[[TYPES.BigInt]]</code></td>
89 * <td><code>string</code></td>
90 * <td>✓</td>
91 * <td>✓</td>
92 * </tr>
93 * <tr>
94 * <td><code>numeric</code><sup>2</sup></td>
95 * <td><code>[[TYPES.Numeric]]</code></td>
96 * <td><code>number</code></td>
97 * <td>✓</td>
98 * <td>✓</td>
99 * </tr>
100 * <tr>
101 * <td><code>decimal</code><sup>2</sup></td>
102 * <td><code>[[TYPES.Decimal]]</code></td>
103 * <td><code>number</code></td>
104 * <td>✓</td>
105 * <td>✓</td>
106 * </tr>
107 * <tr>
108 * <td><code>smallmoney</code></td>
109 * <td><code>[[TYPES.SmallMoney]]</code></td>
110 * <td><code>number</code></td>
111 * <td>✓</td>
112 * <td>✓</td>
113 * </tr>
114 * <tr>
115 * <td><code>money</code></td>
116 * <td><code>[[TYPES.Money]]</code></td>
117 * <td><code>number</code></td>
118 * <td>✓</td>
119 * <td>✓</td>
120 * </tr>
121 * </tbody>
122 *
123 * <tbody>
124 * <tr class="group-heading">
125 * <th colspan="5">Approximate numerics</th>
126 * </tr>
127 * <tr>
128 * <td><code>float</code></td>
129 * <td><code>[[TYPES.Float]]</code></td>
130 * <td><code>number</code></td>
131 * <td>✓</td>
132 * <td>✓</td>
133 * </tr>
134 * <tr>
135 * <td><code>real</code></td>
136 * <td><code>[[TYPES.Real]]</code></td>
137 * <td><code>number</code></td>
138 * <td>✓</td>
139 * <td>✓</td>
140 * </tr>
141 * </tbody>
142 *
143 * <tbody>
144 * <tr class="group-heading">
145 * <th colspan="4">Date and Time</th>
146 * </tr>
147 * <tr>
148 * <td><code>smalldatetime</code></td>
149 * <td><code>[[TYPES.SmallDateTime]]</code></td>
150 * <td><code>Date</code></td>
151 * <td>✓</td>
152 * <td>✓</td>
153 * </tr>
154 * <tr>
155 * <td><code>datetime</code></td>
156 * <td><code>[[TYPES.DateTime]]</code></td>
157 * <td><code>Date</code></td>
158 * <td>✓</td>
159 * <td>✓</td>
160 * </tr>
161 * <tr>
162 * <td><code>datetime2</code></td>
163 * <td><code>[[TYPES.DateTime2]]</code></td>
164 * <td><code>Date</code></td>
165 * <td>✓</td>
166 * <td>✓</td>
167 * </tr>
168 * <tr>
169 * <td><code>datetimeoffset</code></td>
170 * <td><code>[[TYPES.DateTimeOffset]]</code></td>
171 * <td><code>Date</code></td>
172 * <td>✓</td>
173 * <td>✓</td>
174 * </tr>
175 * <tr>
176 * <td><code>time</code></td>
177 * <td><code>[[TYPES.Time]]</code></td>
178 * <td><code>Date</code></td>
179 * <td>✓</td>
180 * <td>✓</td>
181 * </tr>
182 * <tr>
183 * <td><code>date</code></td>
184 * <td><code>[[TYPES.Date]]</code></td>
185 * <td><code>Date</code></td>
186 * <td>✓</td>
187 * <td>✓</td>
188 * </tr>
189 * </tbody>
190 *
191 * <tbody>
192 * <tr class="group-heading">
193 * <th colspan="4">Character Strings</th>
194 * </tr>
195 * <tr>
196 * <td><code>char</code></td>
197 * <td><code>[[TYPES.Char]]</code></td>
198 * <td><code>string</code></td>
199 * <td>✓</td>
200 * <td>✓</td>
201 * </tr>
202 * <tr>
203 * <td><code>varchar</code><sup>3</sup></td>
204 * <td><code>[[TYPES.VarChar]]</code></td>
205 * <td><code>string</code></td>
206 * <td>✓</td>
207 * <td>✓</td>
208 * </tr>
209 * <tr>
210 * <td><code>text</code></td>
211 * <td><code>[[TYPES.Text]]</code></td>
212 * <td><code>string</code></td>
213 * <td>✓</td>
214 * <td>✓</td>
215 * </tr>
216 * </tbody>
217 *
218 * <tbody>
219 * <tr class="group-heading">
220 * <th colspan="4">Unicode Strings</th>
221 * </tr>
222 * <tr>
223 * <td><code>nchar</code></td>
224 * <td><code>[[TYPES.NChar]]</code></td>
225 * <td><code>string</code></td>
226 * <td>✓</td>
227 * <td>✓</td>
228 * </tr>
229 * <tr>
230 * <td><code>nvarchar</code><sup>3</sup></td>
231 * <td><code>[[TYPES.NVarChar]]</code></td>
232 * <td><code>string</code></td>
233 * <td>✓</td>
234 * <td>✓</td>
235 * </tr>
236 * <tr>
237 * <td><code>ntext</code></td>
238 * <td><code>[[TYPES.NText]]</code></td>
239 * <td><code>string</code></td>
240 * <td>✓</td>
241 * <td>-</td>
242 * </tr>
243 * </tbody>
244 *
245 * <tbody>
246 * <tr class="group-heading">
247 * <th colspan="5">Binary Strings<sup>4</sup></th>
248 * </tr>
249 * <tr>
250 * <td><code>binary</code></td>
251 * <td><code>[[TYPES.Binary]]</code></td>
252 * <td><code>Buffer</code></td>
253 * <td>✓</td>
254 * <td>✓</td>
255 * </tr>
256 * <tr>
257 * <td><code>varbinary</code></td>
258 * <td><code>[[TYPES.VarBinary]]</code></td>
259 * <td><code>Buffer</code></td>
260 * <td>✓</td>
261 * <td>✓</td>
262 * </tr>
263 * <tr>
264 * <td><code>image</code></td>
265 * <td><code>[[TYPES.Image]]</code></td>
266 * <td><code>Buffer</code></td>
267 * <td>✓</td>
268 * <td>✓</td>
269 * </tr>
270 * </tbody>
271 *
272 * <tbody>
273 * <tr class="group-heading">
274 * <th colspan="5">Other Data Types</th>
275 * </tr>
276 * <tr>
277 * <td><code>TVP</code></td>
278 * <td><code>[[TYPES.TVP]]</code></td>
279 * <td><code>Object</code></td>
280 * <td>-</td>
281 * <td>✓</td>
282 * </tr>
283 * <tr>
284 * <td><code>UDT</code></td>
285 * <td><code>[[TYPES.UDT]]</code></td>
286 * <td><code>Buffer</code></td>
287 * <td>✓</td>
288 * <td>-</td>
289 * </tr>
290 * <tr>
291 * <td><code>uniqueidentifier</code><sup>4</sup></td>
292 * <td><code>[[TYPES.UniqueIdentifier]]</code></td>
293 * <td><code>string</code></td>
294 * <td>✓</td>
295 * <td>✓</td>
296 * </tr>
297 * <tr>
298 * <td><code>variant</code></td>
299 * <td><code>[[TYPES.Variant]]</code></td>
300 * <td><code>any</code></td>
301 * <td>✓</td>
302 * <td>-</td>
303 * </tr>
304 * <tr>
305 * <td><code>xml</code></td>
306 * <td><code>[[TYPES.Xml]]</code></td>
307 * <td><code>string</code></td>
308 * <td>✓</td>
309 * <td>-</td>
310 * </tr>
311 * </tbody>
312 * </table>
313 *
314 * <ol>
315 * <li>
316 * <h4>BigInt</h4>
317 * <p>
318 * Values are returned as a string. This is because values can exceed 53 bits of significant data, which is greater than a
319 * Javascript <code>number</code> type can represent as an integer.
320 * </p>
321 * </li>
322 * <li>
323 * <h4>Numerical, Decimal</h4>
324 * <p>
325 * For input parameters, default precision is 18 and default scale is 0. Maximum supported precision is 19.
326 * </p>
327 * </li>
328 * <li>
329 * <h4>VarChar, NVarChar</h4>
330 * <p>
331 * <code>varchar(max)</code> and <code>nvarchar(max)</code> are also supported.
332 * </p>
333 * </li>
334 * <li>
335 * <h4>UniqueIdentifier</h4>
336 * <p>
337 * Values are returned as a 16 byte hexadecimal string.
338 * </p>
339 * <p>
340 * Note that the order of bytes is not the same as the character representation. See
341 * <a href="http://msdn.microsoft.com/en-us/library/ms190215.aspx">Using uniqueidentifier Data</a>
342 * for an example of the different ordering of bytes.
343 * </p>
344 * </li>
345 * </ol>
346 */
347export declare const TYPES: {
348 TinyInt: DataType;
349 Bit: DataType;
350 SmallInt: DataType;
351 Int: DataType;
352 SmallDateTime: DataType;
353 Real: DataType;
354 Money: DataType;
355 DateTime: DataType;
356 Float: DataType;
357 Decimal: DataType & {
358 resolvePrecision: (parameter: Parameter) => number;
359 resolveScale: (parameter: Parameter) => number;
360 };
361 Numeric: DataType & {
362 resolveScale: (parameter: Parameter) => number;
363 resolvePrecision: (parameter: Parameter) => number;
364 };
365 SmallMoney: DataType;
366 BigInt: DataType;
367 Image: DataType;
368 Text: DataType;
369 UniqueIdentifier: DataType;
370 NText: DataType;
371 VarBinary: {
372 maximumLength: number;
373 } & DataType;
374 VarChar: {
375 maximumLength: number;
376 } & DataType;
377 Binary: {
378 maximumLength: number;
379 } & DataType;
380 Char: {
381 maximumLength: number;
382 } & DataType;
383 NVarChar: {
384 maximumLength: number;
385 } & DataType;
386 NChar: DataType & {
387 maximumLength: number;
388 };
389 Xml: DataType;
390 Time: DataType;
391 Date: DataType;
392 DateTime2: DataType & {
393 resolveScale: (parameter: Parameter) => number;
394 };
395 DateTimeOffset: DataType & {
396 resolveScale: (parameter: Parameter) => number;
397 };
398 UDT: DataType;
399 TVP: DataType;
400 Variant: DataType;
401};
402export declare const typeByName: {
403 TinyInt: DataType;
404 Bit: DataType;
405 SmallInt: DataType;
406 Int: DataType;
407 SmallDateTime: DataType;
408 Real: DataType;
409 Money: DataType;
410 DateTime: DataType;
411 Float: DataType;
412 Decimal: DataType & {
413 resolvePrecision: (parameter: Parameter) => number;
414 resolveScale: (parameter: Parameter) => number;
415 };
416 Numeric: DataType & {
417 resolveScale: (parameter: Parameter) => number;
418 resolvePrecision: (parameter: Parameter) => number;
419 };
420 SmallMoney: DataType;
421 BigInt: DataType;
422 Image: DataType;
423 Text: DataType;
424 UniqueIdentifier: DataType;
425 NText: DataType;
426 VarBinary: {
427 maximumLength: number;
428 } & DataType;
429 VarChar: {
430 maximumLength: number;
431 } & DataType;
432 Binary: {
433 maximumLength: number;
434 } & DataType;
435 Char: {
436 maximumLength: number;
437 } & DataType;
438 NVarChar: {
439 maximumLength: number;
440 } & DataType;
441 NChar: DataType & {
442 maximumLength: number;
443 };
444 Xml: DataType;
445 Time: DataType;
446 Date: DataType;
447 DateTime2: DataType & {
448 resolveScale: (parameter: Parameter) => number;
449 };
450 DateTimeOffset: DataType & {
451 resolveScale: (parameter: Parameter) => number;
452 };
453 UDT: DataType;
454 TVP: DataType;
455 Variant: DataType;
456};