UNPKG

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