@databricks/appkit-ui 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/js/index.js +1 -0
- package/dist/shared/src/index.js +2 -0
- package/dist/shared/src/sql/helpers.d.ts +113 -8
- package/dist/shared/src/sql/helpers.d.ts.map +1 -1
- package/dist/shared/src/sql/helpers.js +116 -7
- package/dist/shared/src/sql/helpers.js.map +1 -1
- package/dist/shared/src/sql/index.js +1 -0
- package/dist/shared/src/sql/types.d.ts +16 -2
- package/dist/shared/src/sql/types.d.ts.map +1 -1
- package/docs/api/appkit/Variable.sql.md +203 -21
- package/docs/app-management.md +2 -2
- package/docs/plugins/analytics.md +7 -2
- package/package.json +1 -1
- package/sbom.cdx.json +1 -1
|
@@ -2,10 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
```ts
|
|
4
4
|
const sql: {
|
|
5
|
+
bigint: SQLNumberMarker & {
|
|
6
|
+
__sql_type: "BIGINT";
|
|
7
|
+
};
|
|
5
8
|
binary: SQLBinaryMarker;
|
|
6
9
|
boolean: SQLBooleanMarker;
|
|
7
10
|
date: SQLDateMarker;
|
|
11
|
+
double: SQLNumberMarker & {
|
|
12
|
+
__sql_type: "DOUBLE";
|
|
13
|
+
};
|
|
14
|
+
float: SQLNumberMarker & {
|
|
15
|
+
__sql_type: "FLOAT";
|
|
16
|
+
};
|
|
17
|
+
int: SQLNumberMarker & {
|
|
18
|
+
__sql_type: "INT";
|
|
19
|
+
};
|
|
8
20
|
number: SQLNumberMarker;
|
|
21
|
+
numeric: SQLNumberMarker & {
|
|
22
|
+
__sql_type: "NUMERIC";
|
|
23
|
+
};
|
|
9
24
|
string: SQLStringMarker;
|
|
10
25
|
timestamp: SQLTimestampMarker;
|
|
11
26
|
};
|
|
@@ -16,6 +31,40 @@ SQL helper namespace
|
|
|
16
31
|
|
|
17
32
|
## Type Declaration[](#type-declaration "Direct link to Type Declaration")
|
|
18
33
|
|
|
34
|
+
### bigint()[](#bigint "Direct link to bigint()")
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
bigint(value: string | number | bigint): SQLNumberMarker & {
|
|
38
|
+
__sql_type: "BIGINT";
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Creates a `BIGINT` (64-bit signed integer) parameter. Accepts JS `bigint` so callers can round-trip values outside `Number.MAX_SAFE_INTEGER` without precision loss; for `number` inputs, requires `Number.isSafeInteger(value)`.
|
|
44
|
+
|
|
45
|
+
Rejects values outside the signed 64-bit range `[-2^63, 2^63 - 1]`.
|
|
46
|
+
|
|
47
|
+
#### Parameters[](#parameters "Direct link to Parameters")
|
|
48
|
+
|
|
49
|
+
| Parameter | Type | Description |
|
|
50
|
+
| --------- | -------------------------------- | ------------------------------------------------ |
|
|
51
|
+
| `value` | `string` \| `number` \| `bigint` | Integer number, bigint, or integer-shaped string |
|
|
52
|
+
|
|
53
|
+
#### Returns[](#returns "Direct link to Returns")
|
|
54
|
+
|
|
55
|
+
`SQLNumberMarker` & { `__sql_type`: `"BIGINT"`; }
|
|
56
|
+
|
|
57
|
+
Marker pinned to `BIGINT`
|
|
58
|
+
|
|
59
|
+
#### Example[](#example "Direct link to Example")
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
sql.bigint(42); // { __sql_type: "BIGINT", value: "42" }
|
|
63
|
+
sql.bigint(9007199254740993n); // { __sql_type: "BIGINT", value: "9007199254740993" }
|
|
64
|
+
sql.bigint("9007199254740993"); // { __sql_type: "BIGINT", value: "9007199254740993" }
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
|
|
19
68
|
### binary()[](#binary "Direct link to binary()")
|
|
20
69
|
|
|
21
70
|
```ts
|
|
@@ -25,13 +74,13 @@ binary(value: string | Uint8Array | ArrayBuffer): SQLBinaryMarker;
|
|
|
25
74
|
|
|
26
75
|
Creates a BINARY parameter as hex-encoded STRING Accepts Uint8Array, ArrayBuffer, or hex string Note: Databricks SQL Warehouse doesn't support BINARY as parameter type, so this helper returns a STRING with hex encoding. Use UNHEX(<!-- -->:param<!-- -->) in your SQL.
|
|
27
76
|
|
|
28
|
-
#### Parameters[](#parameters "Direct link to Parameters")
|
|
77
|
+
#### Parameters[](#parameters-1 "Direct link to Parameters")
|
|
29
78
|
|
|
30
79
|
| Parameter | Type | Description |
|
|
31
80
|
| --------- | ----------------------------------------- | -------------------------------------- |
|
|
32
81
|
| `value` | `string` \| `Uint8Array` \| `ArrayBuffer` | Uint8Array, ArrayBuffer, or hex string |
|
|
33
82
|
|
|
34
|
-
#### Returns[](#returns "Direct link to Returns")
|
|
83
|
+
#### Returns[](#returns-1 "Direct link to Returns")
|
|
35
84
|
|
|
36
85
|
`SQLBinaryMarker`
|
|
37
86
|
|
|
@@ -63,13 +112,13 @@ boolean(value: string | number | boolean): SQLBooleanMarker;
|
|
|
63
112
|
|
|
64
113
|
Create a BOOLEAN type parameter Accepts booleans, strings, or numbers
|
|
65
114
|
|
|
66
|
-
#### Parameters[](#parameters-
|
|
115
|
+
#### Parameters[](#parameters-2 "Direct link to Parameters")
|
|
67
116
|
|
|
68
117
|
| Parameter | Type | Description |
|
|
69
118
|
| --------- | --------------------------------- | -------------------------- |
|
|
70
119
|
| `value` | `string` \| `number` \| `boolean` | Boolean, string, or number |
|
|
71
120
|
|
|
72
|
-
#### Returns[](#returns-
|
|
121
|
+
#### Returns[](#returns-2 "Direct link to Returns")
|
|
73
122
|
|
|
74
123
|
`SQLBooleanMarker`
|
|
75
124
|
|
|
@@ -116,13 +165,13 @@ date(value: string | Date): SQLDateMarker;
|
|
|
116
165
|
|
|
117
166
|
Creates a DATE type parameter Accepts Date objects or ISO date strings (YYYY-MM-DD format)
|
|
118
167
|
|
|
119
|
-
#### Parameters[](#parameters-
|
|
168
|
+
#### Parameters[](#parameters-3 "Direct link to Parameters")
|
|
120
169
|
|
|
121
170
|
| Parameter | Type | Description |
|
|
122
171
|
| --------- | ------------------ | ------------------------------ |
|
|
123
172
|
| `value` | `string` \| `Date` | Date object or ISO date string |
|
|
124
173
|
|
|
125
|
-
#### Returns[](#returns-
|
|
174
|
+
#### Returns[](#returns-3 "Direct link to Returns")
|
|
126
175
|
|
|
127
176
|
`SQLDateMarker`
|
|
128
177
|
|
|
@@ -142,6 +191,99 @@ params = { startDate: "2024-01-01" }
|
|
|
142
191
|
|
|
143
192
|
```
|
|
144
193
|
|
|
194
|
+
### double()[](#double "Direct link to double()")
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
double(value: string | number): SQLNumberMarker & {
|
|
198
|
+
__sql_type: "DOUBLE";
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Creates a `DOUBLE` (double-precision, 64-bit) parameter. Same precision as a JS `number`, so `sql.double(value)` is exact for any JS number.
|
|
204
|
+
|
|
205
|
+
#### Parameters[](#parameters-4 "Direct link to Parameters")
|
|
206
|
+
|
|
207
|
+
| Parameter | Type | Description |
|
|
208
|
+
| --------- | -------------------- | ------------------------ |
|
|
209
|
+
| `value` | `string` \| `number` | Number or numeric string |
|
|
210
|
+
|
|
211
|
+
#### Returns[](#returns-4 "Direct link to Returns")
|
|
212
|
+
|
|
213
|
+
`SQLNumberMarker` & { `__sql_type`: `"DOUBLE"`; }
|
|
214
|
+
|
|
215
|
+
Marker pinned to `DOUBLE`
|
|
216
|
+
|
|
217
|
+
#### Example[](#example-1 "Direct link to Example")
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
sql.double(3.14); // { __sql_type: "DOUBLE", value: "3.14" }
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### float()[](#float "Direct link to float()")
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
float(value: string | number): SQLNumberMarker & {
|
|
228
|
+
__sql_type: "FLOAT";
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Creates a `FLOAT` (single-precision, 32-bit) parameter. Note that JS numbers are 64-bit doubles, so values may be rounded to fit FLOAT precision at bind time.
|
|
234
|
+
|
|
235
|
+
#### Parameters[](#parameters-5 "Direct link to Parameters")
|
|
236
|
+
|
|
237
|
+
| Parameter | Type | Description |
|
|
238
|
+
| --------- | -------------------- | ------------------------ |
|
|
239
|
+
| `value` | `string` \| `number` | Number or numeric string |
|
|
240
|
+
|
|
241
|
+
#### Returns[](#returns-5 "Direct link to Returns")
|
|
242
|
+
|
|
243
|
+
`SQLNumberMarker` & { `__sql_type`: `"FLOAT"`; }
|
|
244
|
+
|
|
245
|
+
Marker pinned to `FLOAT`
|
|
246
|
+
|
|
247
|
+
#### Example[](#example-2 "Direct link to Example")
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
sql.float(3.14); // { __sql_type: "FLOAT", value: "3.14" }
|
|
251
|
+
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### int()[](#int "Direct link to int()")
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
int(value: string | number): SQLNumberMarker & {
|
|
258
|
+
__sql_type: "INT";
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Creates an `INT` (32-bit signed integer) parameter. Use when the column or context requires `INT` specifically (e.g. legacy schemas, or to make the wire type explicit).
|
|
264
|
+
|
|
265
|
+
Rejects non-integers, values outside `Number.MAX_SAFE_INTEGER` (for number inputs), and values outside the signed 32-bit range `[-2^31, 2^31 - 1]`.
|
|
266
|
+
|
|
267
|
+
#### Parameters[](#parameters-6 "Direct link to Parameters")
|
|
268
|
+
|
|
269
|
+
| Parameter | Type | Description |
|
|
270
|
+
| --------- | -------------------- | --------------------------------------- |
|
|
271
|
+
| `value` | `string` \| `number` | Integer number or integer-shaped string |
|
|
272
|
+
|
|
273
|
+
#### Returns[](#returns-6 "Direct link to Returns")
|
|
274
|
+
|
|
275
|
+
`SQLNumberMarker` & { `__sql_type`: `"INT"`; }
|
|
276
|
+
|
|
277
|
+
Marker pinned to `INT`
|
|
278
|
+
|
|
279
|
+
#### Example[](#example-3 "Direct link to Example")
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
sql.int(42); // { __sql_type: "INT", value: "42" }
|
|
283
|
+
sql.int("42"); // { __sql_type: "INT", value: "42" }
|
|
284
|
+
|
|
285
|
+
```
|
|
286
|
+
|
|
145
287
|
### number()[](#number "Direct link to number()")
|
|
146
288
|
|
|
147
289
|
```ts
|
|
@@ -149,31 +291,71 @@ number(value: string | number): SQLNumberMarker;
|
|
|
149
291
|
|
|
150
292
|
```
|
|
151
293
|
|
|
152
|
-
Creates a
|
|
294
|
+
Creates a numeric type parameter. The wire SQL type is inferred from the value so the parameter binds correctly in any context, including `LIMIT` and `OFFSET`:
|
|
153
295
|
|
|
154
|
-
|
|
296
|
+
* JS integer in `[-2^31, 2^31 - 1]` → `INT`
|
|
297
|
+
* JS integer outside `INT` but within `Number.MAX_SAFE_INTEGER` → `BIGINT`
|
|
298
|
+
* JS non-integer (`3.14`) → `DOUBLE`
|
|
299
|
+
* integer-shaped string in `INT` range → `INT` (common HTTP-input case)
|
|
300
|
+
* integer-shaped string outside `INT` but within `BIGINT` → `BIGINT`
|
|
301
|
+
* decimal-shaped string (`"123.45"`) → `NUMERIC` (preserves precision)
|
|
302
|
+
|
|
303
|
+
Why default to `INT`? Spark's `LIMIT` and `OFFSET` operators require `IntegerType` specifically — `BIGINT` (`LongType`) is rejected with `INVALID_LIMIT_LIKE_EXPRESSION.DATA_TYPE`. Catalyst auto-widens `INT` to `BIGINT` / `DECIMAL` / `DOUBLE` for wider columns, so `INT` is a strictly better default than `BIGINT`.
|
|
304
|
+
|
|
305
|
+
Throws on `NaN`, `Infinity`, JS integers outside `Number.MAX_SAFE_INTEGER`, integer-shaped strings outside the `BIGINT` range, or non-numeric strings. Reach for `sql.int()`, `sql.bigint()`, `sql.float()`, `sql.double()`, or `sql.numeric()` to override the inferred type.
|
|
306
|
+
|
|
307
|
+
#### Parameters[](#parameters-7 "Direct link to Parameters")
|
|
155
308
|
|
|
156
309
|
| Parameter | Type | Description |
|
|
157
310
|
| --------- | -------------------- | ------------------------ |
|
|
158
311
|
| `value` | `string` \| `number` | Number or numeric string |
|
|
159
312
|
|
|
160
|
-
#### Returns[](#returns-
|
|
313
|
+
#### Returns[](#returns-7 "Direct link to Returns")
|
|
161
314
|
|
|
162
315
|
`SQLNumberMarker`
|
|
163
316
|
|
|
164
|
-
Marker
|
|
317
|
+
Marker for a numeric SQL parameter
|
|
165
318
|
|
|
166
|
-
####
|
|
319
|
+
#### Example[](#example-4 "Direct link to Example")
|
|
167
320
|
|
|
168
321
|
```typescript
|
|
169
|
-
|
|
170
|
-
|
|
322
|
+
sql.number(123); // { __sql_type: "INT", value: "123" }
|
|
323
|
+
sql.number(3_000_000_000); // { __sql_type: "BIGINT", value: "3000000000" }
|
|
324
|
+
sql.number(0.5); // { __sql_type: "DOUBLE", value: "0.5" }
|
|
325
|
+
sql.number("10"); // { __sql_type: "INT", value: "10" }
|
|
326
|
+
sql.number("123.45"); // { __sql_type: "NUMERIC", value: "123.45" }
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### numeric()[](#numeric "Direct link to numeric()")
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
numeric(value: string | number): SQLNumberMarker & {
|
|
334
|
+
__sql_type: "NUMERIC";
|
|
335
|
+
};
|
|
171
336
|
|
|
172
337
|
```
|
|
173
338
|
|
|
339
|
+
Creates a `NUMERIC` (fixed-point DECIMAL) parameter. Use when you need exact decimal arithmetic (currency, percentages) — pass values as strings to avoid JS-number precision loss.
|
|
340
|
+
|
|
341
|
+
Note: passing a JS `number` is accepted but lossy for many values (e.g. `0.1 + 0.2` → `"0.30000000000000004"`). Prefer strings.
|
|
342
|
+
|
|
343
|
+
#### Parameters[](#parameters-8 "Direct link to Parameters")
|
|
344
|
+
|
|
345
|
+
| Parameter | Type | Description |
|
|
346
|
+
| --------- | -------------------- | ---------------------------------------------------------- |
|
|
347
|
+
| `value` | `string` \| `number` | Number or numeric string (strings preferred for precision) |
|
|
348
|
+
|
|
349
|
+
#### Returns[](#returns-8 "Direct link to Returns")
|
|
350
|
+
|
|
351
|
+
`SQLNumberMarker` & { `__sql_type`: `"NUMERIC"`; }
|
|
352
|
+
|
|
353
|
+
Marker pinned to `NUMERIC`
|
|
354
|
+
|
|
355
|
+
#### Example[](#example-5 "Direct link to Example")
|
|
356
|
+
|
|
174
357
|
```typescript
|
|
175
|
-
|
|
176
|
-
params = { userId: "123" }
|
|
358
|
+
sql.numeric("12345.6789"); // { __sql_type: "NUMERIC", value: "12345.6789" }
|
|
177
359
|
|
|
178
360
|
```
|
|
179
361
|
|
|
@@ -186,19 +368,19 @@ string(value: string | number | boolean): SQLStringMarker;
|
|
|
186
368
|
|
|
187
369
|
Creates a STRING type parameter Accepts strings, numbers, or booleans
|
|
188
370
|
|
|
189
|
-
#### Parameters[](#parameters-
|
|
371
|
+
#### Parameters[](#parameters-9 "Direct link to Parameters")
|
|
190
372
|
|
|
191
373
|
| Parameter | Type | Description |
|
|
192
374
|
| --------- | --------------------------------- | -------------------------- |
|
|
193
375
|
| `value` | `string` \| `number` \| `boolean` | String, number, or boolean |
|
|
194
376
|
|
|
195
|
-
#### Returns[](#returns-
|
|
377
|
+
#### Returns[](#returns-9 "Direct link to Returns")
|
|
196
378
|
|
|
197
379
|
`SQLStringMarker`
|
|
198
380
|
|
|
199
381
|
Marker object for STRING type parameter
|
|
200
382
|
|
|
201
|
-
#### Examples[](#examples-
|
|
383
|
+
#### Examples[](#examples-3 "Direct link to Examples")
|
|
202
384
|
|
|
203
385
|
```typescript
|
|
204
386
|
const params = { name: sql.string("John") };
|
|
@@ -227,19 +409,19 @@ timestamp(value: string | number | Date): SQLTimestampMarker;
|
|
|
227
409
|
|
|
228
410
|
Creates a TIMESTAMP type parameter Accepts Date objects, ISO timestamp strings, or Unix timestamp numbers
|
|
229
411
|
|
|
230
|
-
#### Parameters[](#parameters-
|
|
412
|
+
#### Parameters[](#parameters-10 "Direct link to Parameters")
|
|
231
413
|
|
|
232
414
|
| Parameter | Type | Description |
|
|
233
415
|
| --------- | ------------------------------ | ----------------------------------------------------------- |
|
|
234
416
|
| `value` | `string` \| `number` \| `Date` | Date object, ISO timestamp string, or Unix timestamp number |
|
|
235
417
|
|
|
236
|
-
#### Returns[](#returns-
|
|
418
|
+
#### Returns[](#returns-10 "Direct link to Returns")
|
|
237
419
|
|
|
238
420
|
`SQLTimestampMarker`
|
|
239
421
|
|
|
240
422
|
Marker object for TIMESTAMP type parameter
|
|
241
423
|
|
|
242
|
-
#### Examples[](#examples-
|
|
424
|
+
#### Examples[](#examples-4 "Direct link to Examples")
|
|
243
425
|
|
|
244
426
|
```typescript
|
|
245
427
|
const params = { createdTime: sql.timestamp(new Date("2024-01-01T12:00:00Z")) };
|
package/docs/app-management.md
CHANGED
|
@@ -40,16 +40,21 @@ Use `:paramName` placeholders and optionally annotate parameter types using SQL
|
|
|
40
40
|
```sql
|
|
41
41
|
-- @param startDate DATE
|
|
42
42
|
-- @param endDate DATE
|
|
43
|
-
-- @param limit
|
|
43
|
+
-- @param limit INT
|
|
44
44
|
SELECT ...
|
|
45
45
|
WHERE usage_date BETWEEN :startDate AND :endDate
|
|
46
46
|
LIMIT :limit
|
|
47
47
|
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
`LIMIT` / `OFFSET` require Spark `IntegerType` specifically — `BIGINT` (`LongType`) is rejected with `INVALID_LIMIT_LIKE_EXPRESSION.DATA_TYPE`. Annotate with `INT`, or use `sql.number()` (auto-infers `INT` for values in `[-2^31, 2^31-1]`, falling back to `BIGINT` for wider values) / `sql.int()` at the call site.
|
|
51
|
+
|
|
50
52
|
**Supported `-- @param` types** (case-insensitive):
|
|
51
53
|
|
|
52
|
-
* `STRING`, `
|
|
54
|
+
* `STRING`, `BOOLEAN`, `DATE`, `TIMESTAMP`, `BINARY`
|
|
55
|
+
* `INT`, `BIGINT`, `TINYINT`, `SMALLINT` — bind via `sql.int()` / `sql.bigint()`
|
|
56
|
+
* `FLOAT`, `DOUBLE` — bind via `sql.float()` / `sql.double()`
|
|
57
|
+
* `NUMERIC`, `DECIMAL` — bind via `sql.numeric()` (pass strings for precision)
|
|
53
58
|
|
|
54
59
|
## Server-injected parameters[](#server-injected-parameters "Direct link to Server-injected parameters")
|
|
55
60
|
|