@simplysm/orm-common 13.0.83 → 13.0.85
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/ddl/initialize.d.ts +2 -2
- package/dist/ddl/initialize.js +1 -1
- package/dist/ddl/initialize.js.map +1 -1
- package/dist/ddl/table-ddl.d.ts +1 -1
- package/dist/exec/queryable.d.ts +115 -115
- package/dist/exec/queryable.js +68 -68
- package/dist/exec/queryable.js.map +1 -1
- package/dist/expr/expr.d.ts +248 -248
- package/dist/expr/expr.js +250 -250
- package/dist/query-builder/base/expr-renderer-base.d.ts +7 -7
- package/dist/query-builder/mssql/mssql-expr-renderer.d.ts +3 -3
- package/dist/query-builder/mssql/mssql-expr-renderer.d.ts.map +1 -1
- package/dist/query-builder/mssql/mssql-expr-renderer.js +5 -5
- package/dist/query-builder/mssql/mssql-query-builder.d.ts +2 -2
- package/dist/query-builder/mssql/mssql-query-builder.d.ts.map +1 -1
- package/dist/query-builder/mssql/mssql-query-builder.js +7 -7
- package/dist/query-builder/mysql/mysql-expr-renderer.d.ts +2 -2
- package/dist/query-builder/mysql/mysql-expr-renderer.d.ts.map +1 -1
- package/dist/query-builder/mysql/mysql-expr-renderer.js +4 -4
- package/dist/query-builder/mysql/mysql-query-builder.d.ts +10 -10
- package/dist/query-builder/mysql/mysql-query-builder.d.ts.map +1 -1
- package/dist/query-builder/mysql/mysql-query-builder.js +4 -4
- package/dist/query-builder/postgresql/postgresql-expr-renderer.d.ts +2 -2
- package/dist/query-builder/postgresql/postgresql-expr-renderer.d.ts.map +1 -1
- package/dist/query-builder/postgresql/postgresql-expr-renderer.js +4 -4
- package/dist/query-builder/postgresql/postgresql-query-builder.d.ts +8 -8
- package/dist/query-builder/postgresql/postgresql-query-builder.d.ts.map +1 -1
- package/dist/query-builder/postgresql/postgresql-query-builder.js +7 -7
- package/dist/query-builder/query-builder.d.ts +1 -1
- package/dist/schema/factory/column-builder.d.ts +46 -46
- package/dist/schema/factory/column-builder.js +25 -25
- package/dist/schema/factory/index-builder.d.ts +22 -22
- package/dist/schema/factory/index-builder.js +14 -14
- package/dist/schema/factory/relation-builder.d.ts +93 -93
- package/dist/schema/factory/relation-builder.d.ts.map +1 -1
- package/dist/schema/factory/relation-builder.js +37 -37
- package/dist/schema/procedure-builder.d.ts +38 -38
- package/dist/schema/procedure-builder.d.ts.map +1 -1
- package/dist/schema/procedure-builder.js +26 -26
- package/dist/schema/table-builder.d.ts +38 -38
- package/dist/schema/table-builder.d.ts.map +1 -1
- package/dist/schema/table-builder.js +29 -29
- package/dist/schema/view-builder.d.ts +26 -26
- package/dist/schema/view-builder.d.ts.map +1 -1
- package/dist/schema/view-builder.js +18 -18
- package/dist/types/db.d.ts +40 -40
- package/dist/types/expr.d.ts +75 -75
- package/dist/types/expr.d.ts.map +1 -1
- package/dist/types/query-def.d.ts +32 -32
- package/dist/types/query-def.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/ddl/initialize.ts +16 -16
- package/src/ddl/table-ddl.ts +1 -1
- package/src/exec/queryable.ts +163 -163
- package/src/expr/expr.ts +257 -257
- package/src/query-builder/base/expr-renderer-base.ts +8 -8
- package/src/query-builder/mssql/mssql-expr-renderer.ts +20 -20
- package/src/query-builder/mssql/mssql-query-builder.ts +28 -28
- package/src/query-builder/mysql/mysql-expr-renderer.ts +22 -22
- package/src/query-builder/mysql/mysql-query-builder.ts +65 -65
- package/src/query-builder/postgresql/postgresql-expr-renderer.ts +15 -15
- package/src/query-builder/postgresql/postgresql-query-builder.ts +43 -43
- package/src/query-builder/query-builder.ts +1 -1
- package/src/schema/factory/column-builder.ts +48 -48
- package/src/schema/factory/index-builder.ts +22 -22
- package/src/schema/factory/relation-builder.ts +95 -95
- package/src/schema/procedure-builder.ts +38 -38
- package/src/schema/table-builder.ts +38 -38
- package/src/schema/view-builder.ts +28 -28
- package/src/types/db.ts +41 -41
- package/src/types/expr.ts +79 -79
- package/src/types/query-def.ts +37 -37
- package/tests/ddl/basic.expected.ts +8 -8
package/dist/expr/expr.d.ts
CHANGED
|
@@ -52,9 +52,9 @@ export declare const expr: {
|
|
|
52
52
|
*
|
|
53
53
|
* Widen to base type matching dataType, remove literal type
|
|
54
54
|
*
|
|
55
|
-
* @param dataType -
|
|
56
|
-
* @param value -
|
|
57
|
-
* @returns
|
|
55
|
+
* @param dataType - The data type of the value ("string", "number", "boolean", "DateTime", "DateOnly", "Time", "Uuid", "Buffer")
|
|
56
|
+
* @param value - Value to wrap (undefined allowed)
|
|
57
|
+
* @returns Wrapped ExprUnit instance
|
|
58
58
|
*
|
|
59
59
|
* @example
|
|
60
60
|
* ```typescript
|
|
@@ -185,16 +185,16 @@ export declare const expr: {
|
|
|
185
185
|
/**
|
|
186
186
|
* range comparison (BETWEEN)
|
|
187
187
|
*
|
|
188
|
-
* from/to
|
|
188
|
+
* If from/to is undefined, that direction is unbounded
|
|
189
189
|
*
|
|
190
190
|
* @param source - Column or expression to compare
|
|
191
|
-
* @param from -
|
|
192
|
-
* @param to -
|
|
191
|
+
* @param from - Start value (no lower bound if undefined)
|
|
192
|
+
* @param to - End value (no upper bound if undefined)
|
|
193
193
|
* @returns WHERE condition expression
|
|
194
194
|
*
|
|
195
195
|
* @example
|
|
196
196
|
* ```typescript
|
|
197
|
-
* // range
|
|
197
|
+
* // Specify range
|
|
198
198
|
* db.user().where((u) => [expr.between(u.age, 18, 65)])
|
|
199
199
|
* // WHERE age BETWEEN 18 AND 65
|
|
200
200
|
*
|
|
@@ -205,9 +205,9 @@ export declare const expr: {
|
|
|
205
205
|
*/
|
|
206
206
|
between<T extends ColumnPrimitive>(source: ExprUnit<T>, from?: ExprInput<T>, to?: ExprInput<T>): WhereExprUnit;
|
|
207
207
|
/**
|
|
208
|
-
* NULL
|
|
208
|
+
* NULL check (IS NULL)
|
|
209
209
|
*
|
|
210
|
-
* @param source -
|
|
210
|
+
* @param source - Column or expression to check
|
|
211
211
|
* @returns WHERE condition expression
|
|
212
212
|
*
|
|
213
213
|
* @example
|
|
@@ -218,33 +218,33 @@ export declare const expr: {
|
|
|
218
218
|
*/
|
|
219
219
|
null<T extends ColumnPrimitive>(source: ExprUnit<T>): WhereExprUnit;
|
|
220
220
|
/**
|
|
221
|
-
* LIKE pattern
|
|
221
|
+
* LIKE pattern matching
|
|
222
222
|
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
223
|
+
* `%` matches zero or more characters, `_` matches a single character.
|
|
224
|
+
* Special characters are escaped with `\`
|
|
225
225
|
*
|
|
226
|
-
* @param source -
|
|
227
|
-
* @param pattern -
|
|
226
|
+
* @param source - Column or expression to search
|
|
227
|
+
* @param pattern - Search pattern (%, _ wildcards available)
|
|
228
228
|
* @returns WHERE condition expression
|
|
229
229
|
*
|
|
230
230
|
* @example
|
|
231
231
|
* ```typescript
|
|
232
|
-
* //
|
|
232
|
+
* // Prefix search
|
|
233
233
|
* db.user().where((u) => [expr.like(u.name, "John%")])
|
|
234
234
|
* // WHERE name LIKE 'John%' ESCAPE '\'
|
|
235
235
|
*
|
|
236
|
-
* //
|
|
236
|
+
* // Contains search
|
|
237
237
|
* db.user().where((u) => [expr.like(u.email, "%@gmail.com")])
|
|
238
238
|
* ```
|
|
239
239
|
*/
|
|
240
240
|
like(source: ExprUnit<string | undefined>, pattern: ExprInput<string | undefined>): WhereExprUnit;
|
|
241
241
|
/**
|
|
242
|
-
*
|
|
242
|
+
* Regular expression pattern matching
|
|
243
243
|
*
|
|
244
|
-
*
|
|
244
|
+
* Note: regex syntax may differ between DBMS implementations
|
|
245
245
|
*
|
|
246
|
-
* @param source -
|
|
247
|
-
* @param pattern -
|
|
246
|
+
* @param source - Column or expression to search
|
|
247
|
+
* @param pattern - Regular expression pattern
|
|
248
248
|
* @returns WHERE condition expression
|
|
249
249
|
*
|
|
250
250
|
* @example
|
|
@@ -255,10 +255,10 @@ export declare const expr: {
|
|
|
255
255
|
*/
|
|
256
256
|
regexp(source: ExprUnit<string | undefined>, pattern: ExprInput<string | undefined>): WhereExprUnit;
|
|
257
257
|
/**
|
|
258
|
-
* IN operator -
|
|
258
|
+
* IN operator - Compare against a list of values
|
|
259
259
|
*
|
|
260
260
|
* @param source - Column or expression to compare
|
|
261
|
-
* @param values -
|
|
261
|
+
* @param values - List of values to compare against
|
|
262
262
|
* @returns WHERE condition expression
|
|
263
263
|
*
|
|
264
264
|
* @example
|
|
@@ -269,14 +269,14 @@ export declare const expr: {
|
|
|
269
269
|
*/
|
|
270
270
|
in<T extends ColumnPrimitive>(source: ExprUnit<T>, values: ExprInput<T>[]): WhereExprUnit;
|
|
271
271
|
/**
|
|
272
|
-
* IN (SELECT ...) -
|
|
272
|
+
* IN (SELECT ...) - Compare against subquery results
|
|
273
273
|
*
|
|
274
|
-
*
|
|
274
|
+
* The subquery must SELECT only a single column
|
|
275
275
|
*
|
|
276
276
|
* @param source - Column or expression to compare
|
|
277
|
-
* @param query -
|
|
277
|
+
* @param query - Queryable that returns a single column
|
|
278
278
|
* @returns WHERE condition expression
|
|
279
|
-
* @throws {Error}
|
|
279
|
+
* @throws {Error} When the subquery does not return a single column
|
|
280
280
|
*
|
|
281
281
|
* @example
|
|
282
282
|
* ```typescript
|
|
@@ -293,16 +293,16 @@ export declare const expr: {
|
|
|
293
293
|
*/
|
|
294
294
|
inQuery<T extends ColumnPrimitive, TData extends Record<string, T>>(source: ExprUnit<T>, query: Queryable<TData, any>): WhereExprUnit;
|
|
295
295
|
/**
|
|
296
|
-
* EXISTS (SELECT ...) -
|
|
296
|
+
* EXISTS (SELECT ...) - Check if subquery returns any rows
|
|
297
297
|
*
|
|
298
|
-
*
|
|
298
|
+
* Returns true if the subquery returns one or more rows
|
|
299
299
|
*
|
|
300
|
-
* @param query -
|
|
300
|
+
* @param query - Queryable to check for existence
|
|
301
301
|
* @returns WHERE condition expression
|
|
302
302
|
*
|
|
303
303
|
* @example
|
|
304
304
|
* ```typescript
|
|
305
|
-
* //
|
|
305
|
+
* // Query users who have orders
|
|
306
306
|
* db.user().where((u) => [
|
|
307
307
|
* expr.exists(
|
|
308
308
|
* db.order().where((o) => [expr.eq(o.userId, u.id)])
|
|
@@ -313,10 +313,10 @@ export declare const expr: {
|
|
|
313
313
|
*/
|
|
314
314
|
exists(query: Queryable<any, any>): WhereExprUnit;
|
|
315
315
|
/**
|
|
316
|
-
* NOT operator -
|
|
316
|
+
* NOT operator - Negate a condition
|
|
317
317
|
*
|
|
318
|
-
* @param arg -
|
|
319
|
-
* @returns
|
|
318
|
+
* @param arg - Condition to negate
|
|
319
|
+
* @returns Negated WHERE condition expression
|
|
320
320
|
*
|
|
321
321
|
* @example
|
|
322
322
|
* ```typescript
|
|
@@ -326,12 +326,12 @@ export declare const expr: {
|
|
|
326
326
|
*/
|
|
327
327
|
not(arg: WhereExprUnit): WhereExprUnit;
|
|
328
328
|
/**
|
|
329
|
-
* AND operator -
|
|
329
|
+
* AND operator - All conditions must be satisfied
|
|
330
330
|
*
|
|
331
|
-
*
|
|
331
|
+
* Combines multiple conditions with AND. Passing an array to where() automatically applies AND
|
|
332
332
|
*
|
|
333
|
-
* @param conditions -
|
|
334
|
-
* @returns
|
|
333
|
+
* @param conditions - List of conditions to combine with AND
|
|
334
|
+
* @returns Combined WHERE condition expression
|
|
335
335
|
*
|
|
336
336
|
* @example
|
|
337
337
|
* ```typescript
|
|
@@ -346,10 +346,10 @@ export declare const expr: {
|
|
|
346
346
|
*/
|
|
347
347
|
and(conditions: WhereExprUnit[]): WhereExprUnit;
|
|
348
348
|
/**
|
|
349
|
-
* OR operator -
|
|
349
|
+
* OR operator - At least one condition must be satisfied
|
|
350
350
|
*
|
|
351
|
-
* @param conditions -
|
|
352
|
-
* @returns
|
|
351
|
+
* @param conditions - List of conditions to combine with OR
|
|
352
|
+
* @returns Combined WHERE condition expression
|
|
353
353
|
*
|
|
354
354
|
* @example
|
|
355
355
|
* ```typescript
|
|
@@ -364,12 +364,12 @@ export declare const expr: {
|
|
|
364
364
|
*/
|
|
365
365
|
or(conditions: WhereExprUnit[]): WhereExprUnit;
|
|
366
366
|
/**
|
|
367
|
-
*
|
|
367
|
+
* String concatenation (CONCAT)
|
|
368
368
|
*
|
|
369
|
-
* NULL
|
|
369
|
+
* NULL values are treated as empty strings (auto-transformed per DBMS)
|
|
370
370
|
*
|
|
371
|
-
* @param args -
|
|
372
|
-
* @returns
|
|
371
|
+
* @param args - Strings to concatenate
|
|
372
|
+
* @returns Concatenated string expression
|
|
373
373
|
*
|
|
374
374
|
* @example
|
|
375
375
|
* ```typescript
|
|
@@ -381,11 +381,11 @@ export declare const expr: {
|
|
|
381
381
|
*/
|
|
382
382
|
concat(...args: ExprInput<string | undefined>[]): ExprUnit<string>;
|
|
383
383
|
/**
|
|
384
|
-
*
|
|
384
|
+
* Extract specified length from the left of a string (LEFT)
|
|
385
385
|
*
|
|
386
|
-
* @param source -
|
|
387
|
-
* @param length -
|
|
388
|
-
* @returns
|
|
386
|
+
* @param source - Original string
|
|
387
|
+
* @param length - Number of characters to extract
|
|
388
|
+
* @returns Extracted string expression
|
|
389
389
|
*
|
|
390
390
|
* @example
|
|
391
391
|
* ```typescript
|
|
@@ -397,11 +397,11 @@ export declare const expr: {
|
|
|
397
397
|
*/
|
|
398
398
|
left<T extends string | undefined>(source: ExprUnit<T>, length: ExprInput<number>): ExprUnit<T>;
|
|
399
399
|
/**
|
|
400
|
-
*
|
|
400
|
+
* Extract specified length from the right of a string (RIGHT)
|
|
401
401
|
*
|
|
402
|
-
* @param source -
|
|
403
|
-
* @param length -
|
|
404
|
-
* @returns
|
|
402
|
+
* @param source - Original string
|
|
403
|
+
* @param length - Number of characters to extract
|
|
404
|
+
* @returns Extracted string expression
|
|
405
405
|
*
|
|
406
406
|
* @example
|
|
407
407
|
* ```typescript
|
|
@@ -413,10 +413,10 @@ export declare const expr: {
|
|
|
413
413
|
*/
|
|
414
414
|
right<T extends string | undefined>(source: ExprUnit<T>, length: ExprInput<number>): ExprUnit<T>;
|
|
415
415
|
/**
|
|
416
|
-
*
|
|
416
|
+
* Remove whitespace from both sides of a string (TRIM)
|
|
417
417
|
*
|
|
418
|
-
* @param source -
|
|
419
|
-
* @returns
|
|
418
|
+
* @param source - Original string
|
|
419
|
+
* @returns String expression with whitespace removed
|
|
420
420
|
*
|
|
421
421
|
* @example
|
|
422
422
|
* ```typescript
|
|
@@ -428,14 +428,14 @@ export declare const expr: {
|
|
|
428
428
|
*/
|
|
429
429
|
trim<T extends string | undefined>(source: ExprUnit<T>): ExprUnit<T>;
|
|
430
430
|
/**
|
|
431
|
-
*
|
|
431
|
+
* Left padding (LPAD)
|
|
432
432
|
*
|
|
433
|
-
*
|
|
433
|
+
* Repeatedly adds fillString on the left until the target length is reached
|
|
434
434
|
*
|
|
435
|
-
* @param source -
|
|
436
|
-
* @param length -
|
|
437
|
-
* @param fillString -
|
|
438
|
-
* @returns
|
|
435
|
+
* @param source - Original string
|
|
436
|
+
* @param length - Target length
|
|
437
|
+
* @param fillString - String to use for padding
|
|
438
|
+
* @returns Padded string expression
|
|
439
439
|
*
|
|
440
440
|
* @example
|
|
441
441
|
* ```typescript
|
|
@@ -448,12 +448,12 @@ export declare const expr: {
|
|
|
448
448
|
*/
|
|
449
449
|
padStart<T extends string | undefined>(source: ExprUnit<T>, length: ExprInput<number>, fillString: ExprInput<string>): ExprUnit<T>;
|
|
450
450
|
/**
|
|
451
|
-
*
|
|
451
|
+
* String replacement (REPLACE)
|
|
452
452
|
*
|
|
453
|
-
* @param source -
|
|
454
|
-
* @param from -
|
|
455
|
-
* @param to -
|
|
456
|
-
* @returns
|
|
453
|
+
* @param source - Original string
|
|
454
|
+
* @param from - String to find
|
|
455
|
+
* @param to - Replacement string
|
|
456
|
+
* @returns Replaced string expression
|
|
457
457
|
*
|
|
458
458
|
* @example
|
|
459
459
|
* ```typescript
|
|
@@ -465,10 +465,10 @@ export declare const expr: {
|
|
|
465
465
|
*/
|
|
466
466
|
replace<T extends string | undefined>(source: ExprUnit<T>, from: ExprInput<string>, to: ExprInput<string>): ExprUnit<T>;
|
|
467
467
|
/**
|
|
468
|
-
*
|
|
468
|
+
* Convert string to uppercase (UPPER)
|
|
469
469
|
*
|
|
470
|
-
* @param source -
|
|
471
|
-
* @returns
|
|
470
|
+
* @param source - Original string
|
|
471
|
+
* @returns Uppercase string expression
|
|
472
472
|
*
|
|
473
473
|
* @example
|
|
474
474
|
* ```typescript
|
|
@@ -480,10 +480,10 @@ export declare const expr: {
|
|
|
480
480
|
*/
|
|
481
481
|
upper<T extends string | undefined>(source: ExprUnit<T>): ExprUnit<T>;
|
|
482
482
|
/**
|
|
483
|
-
*
|
|
483
|
+
* Convert string to lowercase (LOWER)
|
|
484
484
|
*
|
|
485
|
-
* @param source -
|
|
486
|
-
* @returns
|
|
485
|
+
* @param source - Original string
|
|
486
|
+
* @returns Lowercase string expression
|
|
487
487
|
*
|
|
488
488
|
* @example
|
|
489
489
|
* ```typescript
|
|
@@ -495,10 +495,10 @@ export declare const expr: {
|
|
|
495
495
|
*/
|
|
496
496
|
lower<T extends string | undefined>(source: ExprUnit<T>): ExprUnit<T>;
|
|
497
497
|
/**
|
|
498
|
-
*
|
|
498
|
+
* String length (character count)
|
|
499
499
|
*
|
|
500
|
-
* @param source -
|
|
501
|
-
* @returns
|
|
500
|
+
* @param source - Original string
|
|
501
|
+
* @returns Character count
|
|
502
502
|
*
|
|
503
503
|
* @example
|
|
504
504
|
* ```typescript
|
|
@@ -510,12 +510,12 @@ export declare const expr: {
|
|
|
510
510
|
*/
|
|
511
511
|
length(source: ExprUnit<string | undefined>): ExprUnit<number>;
|
|
512
512
|
/**
|
|
513
|
-
*
|
|
513
|
+
* String byte length
|
|
514
514
|
*
|
|
515
|
-
* UTF-8
|
|
515
|
+
* In UTF-8, CJK characters are 3 bytes each
|
|
516
516
|
*
|
|
517
|
-
* @param source -
|
|
518
|
-
* @returns
|
|
517
|
+
* @param source - Original string
|
|
518
|
+
* @returns Byte count
|
|
519
519
|
*
|
|
520
520
|
* @example
|
|
521
521
|
* ```typescript
|
|
@@ -527,19 +527,19 @@ export declare const expr: {
|
|
|
527
527
|
*/
|
|
528
528
|
byteLength(source: ExprUnit<string | undefined>): ExprUnit<number>;
|
|
529
529
|
/**
|
|
530
|
-
*
|
|
530
|
+
* Extract part of a string (SUBSTRING)
|
|
531
531
|
*
|
|
532
|
-
*
|
|
532
|
+
* Uses 1-based index per SQL standard
|
|
533
533
|
*
|
|
534
|
-
* @param source -
|
|
535
|
-
* @param start -
|
|
536
|
-
* @param length -
|
|
537
|
-
* @returns
|
|
534
|
+
* @param source - Original string
|
|
535
|
+
* @param start - Start position (starting from 1)
|
|
536
|
+
* @param length - Length to extract (to the end if omitted)
|
|
537
|
+
* @returns Extracted string expression
|
|
538
538
|
*
|
|
539
539
|
* @example
|
|
540
540
|
* ```typescript
|
|
541
541
|
* db.user().select((u) => ({
|
|
542
|
-
* // "Hello World"
|
|
542
|
+
* // From "Hello World", 5 characters starting at index 1: "Hello"
|
|
543
543
|
* prefix: expr.substring(u.name, 1, 5),
|
|
544
544
|
* }))
|
|
545
545
|
* // SELECT SUBSTRING(name, 1, 5) AS prefix
|
|
@@ -547,13 +547,13 @@ export declare const expr: {
|
|
|
547
547
|
*/
|
|
548
548
|
substring<T extends string | undefined>(source: ExprUnit<T>, start: ExprInput<number>, length?: ExprInput<number>): ExprUnit<T>;
|
|
549
549
|
/**
|
|
550
|
-
*
|
|
550
|
+
* Find position within a string (LOCATE/CHARINDEX)
|
|
551
551
|
*
|
|
552
|
-
* 1-based index
|
|
552
|
+
* Returns 1-based index, or 0 if not found
|
|
553
553
|
*
|
|
554
|
-
* @param source -
|
|
555
|
-
* @param search -
|
|
556
|
-
* @returns
|
|
554
|
+
* @param source - String to search in
|
|
555
|
+
* @param search - String to find
|
|
556
|
+
* @returns Position (starting from 1, 0 if not found)
|
|
557
557
|
*
|
|
558
558
|
* @example
|
|
559
559
|
* ```typescript
|
|
@@ -566,10 +566,10 @@ export declare const expr: {
|
|
|
566
566
|
*/
|
|
567
567
|
indexOf(source: ExprUnit<string | undefined>, search: ExprInput<string>): ExprUnit<number>;
|
|
568
568
|
/**
|
|
569
|
-
*
|
|
569
|
+
* Absolute value (ABS)
|
|
570
570
|
*
|
|
571
|
-
* @param source -
|
|
572
|
-
* @returns
|
|
571
|
+
* @param source - Original number
|
|
572
|
+
* @returns Absolute value expression
|
|
573
573
|
*
|
|
574
574
|
* @example
|
|
575
575
|
* ```typescript
|
|
@@ -581,11 +581,11 @@ export declare const expr: {
|
|
|
581
581
|
*/
|
|
582
582
|
abs<T extends number | undefined>(source: ExprUnit<T>): ExprUnit<T>;
|
|
583
583
|
/**
|
|
584
|
-
*
|
|
584
|
+
* Round (ROUND)
|
|
585
585
|
*
|
|
586
|
-
* @param source -
|
|
587
|
-
* @param digits -
|
|
588
|
-
* @returns
|
|
586
|
+
* @param source - Original number
|
|
587
|
+
* @param digits - Number of decimal places
|
|
588
|
+
* @returns Rounded number expression
|
|
589
589
|
*
|
|
590
590
|
* @example
|
|
591
591
|
* ```typescript
|
|
@@ -598,10 +598,10 @@ export declare const expr: {
|
|
|
598
598
|
*/
|
|
599
599
|
round<T extends number | undefined>(source: ExprUnit<T>, digits: number): ExprUnit<T>;
|
|
600
600
|
/**
|
|
601
|
-
*
|
|
601
|
+
* Ceiling (CEILING)
|
|
602
602
|
*
|
|
603
|
-
* @param source -
|
|
604
|
-
* @returns
|
|
603
|
+
* @param source - Original number
|
|
604
|
+
* @returns Ceiling number expression
|
|
605
605
|
*
|
|
606
606
|
* @example
|
|
607
607
|
* ```typescript
|
|
@@ -614,10 +614,10 @@ export declare const expr: {
|
|
|
614
614
|
*/
|
|
615
615
|
ceil<T extends number | undefined>(source: ExprUnit<T>): ExprUnit<T>;
|
|
616
616
|
/**
|
|
617
|
-
*
|
|
617
|
+
* Floor (FLOOR)
|
|
618
618
|
*
|
|
619
|
-
* @param source -
|
|
620
|
-
* @returns
|
|
619
|
+
* @param source - Original number
|
|
620
|
+
* @returns Floor number expression
|
|
621
621
|
*
|
|
622
622
|
* @example
|
|
623
623
|
* ```typescript
|
|
@@ -630,10 +630,10 @@ export declare const expr: {
|
|
|
630
630
|
*/
|
|
631
631
|
floor<T extends number | undefined>(source: ExprUnit<T>): ExprUnit<T>;
|
|
632
632
|
/**
|
|
633
|
-
*
|
|
633
|
+
* Extract year (YEAR)
|
|
634
634
|
*
|
|
635
|
-
* @param source - DateTime
|
|
636
|
-
* @returns
|
|
635
|
+
* @param source - DateTime or DateOnly expression
|
|
636
|
+
* @returns Year (4-digit number)
|
|
637
637
|
*
|
|
638
638
|
* @example
|
|
639
639
|
* ```typescript
|
|
@@ -645,10 +645,10 @@ export declare const expr: {
|
|
|
645
645
|
*/
|
|
646
646
|
year<T extends DateTime | DateOnly | undefined>(source: ExprUnit<T>): ExprUnit<T extends undefined ? undefined : number>;
|
|
647
647
|
/**
|
|
648
|
-
*
|
|
648
|
+
* Extract month (MONTH)
|
|
649
649
|
*
|
|
650
|
-
* @param source - DateTime
|
|
651
|
-
* @returns
|
|
650
|
+
* @param source - DateTime or DateOnly expression
|
|
651
|
+
* @returns Month (1~12)
|
|
652
652
|
*
|
|
653
653
|
* @example
|
|
654
654
|
* ```typescript
|
|
@@ -660,10 +660,10 @@ export declare const expr: {
|
|
|
660
660
|
*/
|
|
661
661
|
month<T extends DateTime | DateOnly | undefined>(source: ExprUnit<T>): ExprUnit<T extends undefined ? undefined : number>;
|
|
662
662
|
/**
|
|
663
|
-
*
|
|
663
|
+
* Extract day (DAY)
|
|
664
664
|
*
|
|
665
|
-
* @param source - DateTime
|
|
666
|
-
* @returns
|
|
665
|
+
* @param source - DateTime or DateOnly expression
|
|
666
|
+
* @returns Day (1~31)
|
|
667
667
|
*
|
|
668
668
|
* @example
|
|
669
669
|
* ```typescript
|
|
@@ -675,10 +675,10 @@ export declare const expr: {
|
|
|
675
675
|
*/
|
|
676
676
|
day<T extends DateTime | DateOnly | undefined>(source: ExprUnit<T>): ExprUnit<T extends undefined ? undefined : number>;
|
|
677
677
|
/**
|
|
678
|
-
*
|
|
678
|
+
* Extract hour (HOUR)
|
|
679
679
|
*
|
|
680
|
-
* @param source - DateTime
|
|
681
|
-
* @returns
|
|
680
|
+
* @param source - DateTime or Time expression
|
|
681
|
+
* @returns Hour (0~23)
|
|
682
682
|
*
|
|
683
683
|
* @example
|
|
684
684
|
* ```typescript
|
|
@@ -690,10 +690,10 @@ export declare const expr: {
|
|
|
690
690
|
*/
|
|
691
691
|
hour<T extends DateTime | Time | undefined>(source: ExprUnit<T>): ExprUnit<T extends undefined ? undefined : number>;
|
|
692
692
|
/**
|
|
693
|
-
*
|
|
693
|
+
* Extract minute (MINUTE)
|
|
694
694
|
*
|
|
695
|
-
* @param source - DateTime
|
|
696
|
-
* @returns
|
|
695
|
+
* @param source - DateTime or Time expression
|
|
696
|
+
* @returns Minute (0~59)
|
|
697
697
|
*
|
|
698
698
|
* @example
|
|
699
699
|
* ```typescript
|
|
@@ -705,10 +705,10 @@ export declare const expr: {
|
|
|
705
705
|
*/
|
|
706
706
|
minute<T extends DateTime | Time | undefined>(source: ExprUnit<T>): ExprUnit<T extends undefined ? undefined : number>;
|
|
707
707
|
/**
|
|
708
|
-
*
|
|
708
|
+
* Extract second (SECOND)
|
|
709
709
|
*
|
|
710
|
-
* @param source - DateTime
|
|
711
|
-
* @returns
|
|
710
|
+
* @param source - DateTime or Time expression
|
|
711
|
+
* @returns Second (0~59)
|
|
712
712
|
*
|
|
713
713
|
* @example
|
|
714
714
|
* ```typescript
|
|
@@ -720,12 +720,12 @@ export declare const expr: {
|
|
|
720
720
|
*/
|
|
721
721
|
second<T extends DateTime | Time | undefined>(source: ExprUnit<T>): ExprUnit<T extends undefined ? undefined : number>;
|
|
722
722
|
/**
|
|
723
|
-
* ISO
|
|
723
|
+
* Extract ISO week number
|
|
724
724
|
*
|
|
725
|
-
* ISO 8601
|
|
725
|
+
* ISO 8601 week number (starts Monday, 1~53)
|
|
726
726
|
*
|
|
727
727
|
* @param source - DateOnly expression
|
|
728
|
-
* @returns ISO
|
|
728
|
+
* @returns ISO week number
|
|
729
729
|
*
|
|
730
730
|
* @example
|
|
731
731
|
* ```typescript
|
|
@@ -737,29 +737,29 @@ export declare const expr: {
|
|
|
737
737
|
*/
|
|
738
738
|
isoWeek<T extends DateOnly | undefined>(source: ExprUnit<T>): ExprUnit<T extends undefined ? undefined : number>;
|
|
739
739
|
/**
|
|
740
|
-
* ISO
|
|
740
|
+
* ISO week start date (Monday)
|
|
741
741
|
*
|
|
742
|
-
*
|
|
742
|
+
* Returns the Monday of the week the given date belongs to
|
|
743
743
|
*
|
|
744
744
|
* @param source - DateOnly expression
|
|
745
|
-
* @returns
|
|
745
|
+
* @returns Week start date (Monday)
|
|
746
746
|
*
|
|
747
747
|
* @example
|
|
748
748
|
* ```typescript
|
|
749
749
|
* db.order().select((o) => ({
|
|
750
750
|
* weekStart: expr.isoWeekStartDate(o.orderDate),
|
|
751
751
|
* }))
|
|
752
|
-
* // 2024-01-10 (
|
|
752
|
+
* // 2024-01-10 (Wed) → 2024-01-08 (Mon)
|
|
753
753
|
* ```
|
|
754
754
|
*/
|
|
755
755
|
isoWeekStartDate<T extends DateOnly | undefined>(source: ExprUnit<T>): ExprUnit<T>;
|
|
756
756
|
/**
|
|
757
|
-
* ISO
|
|
757
|
+
* ISO year-month (first day of the month)
|
|
758
758
|
*
|
|
759
|
-
*
|
|
759
|
+
* Returns the first day of the month for the given date
|
|
760
760
|
*
|
|
761
761
|
* @param source - DateOnly expression
|
|
762
|
-
* @returns
|
|
762
|
+
* @returns First day of the month
|
|
763
763
|
*
|
|
764
764
|
* @example
|
|
765
765
|
* ```typescript
|
|
@@ -771,12 +771,12 @@ export declare const expr: {
|
|
|
771
771
|
*/
|
|
772
772
|
isoYearMonth<T extends DateOnly | undefined>(source: ExprUnit<T>): ExprUnit<T>;
|
|
773
773
|
/**
|
|
774
|
-
*
|
|
774
|
+
* Calculate date difference (DATEDIFF)
|
|
775
775
|
*
|
|
776
|
-
* @param unit -
|
|
777
|
-
* @param from -
|
|
778
|
-
* @param to -
|
|
779
|
-
* @returns
|
|
776
|
+
* @param unit - Unit ("year", "month", "day", "hour", "minute", "second")
|
|
777
|
+
* @param from - Start date
|
|
778
|
+
* @param to - End date
|
|
779
|
+
* @returns Difference value (to - from)
|
|
780
780
|
*
|
|
781
781
|
* @example
|
|
782
782
|
* ```typescript
|
|
@@ -788,12 +788,12 @@ export declare const expr: {
|
|
|
788
788
|
*/
|
|
789
789
|
dateDiff<T extends DateTime | DateOnly | Time | undefined>(unit: DateUnit, from: ExprInput<T>, to: ExprInput<T>): ExprUnit<T extends undefined ? undefined : number>;
|
|
790
790
|
/**
|
|
791
|
-
*
|
|
791
|
+
* Add to date (DATEADD)
|
|
792
792
|
*
|
|
793
|
-
* @param unit -
|
|
794
|
-
* @param source -
|
|
795
|
-
* @param value -
|
|
796
|
-
* @returns
|
|
793
|
+
* @param unit - Unit ("year", "month", "day", "hour", "minute", "second")
|
|
794
|
+
* @param source - Original date
|
|
795
|
+
* @param value - Value to add (negative allowed)
|
|
796
|
+
* @returns Calculated date
|
|
797
797
|
*
|
|
798
798
|
* @example
|
|
799
799
|
* ```typescript
|
|
@@ -805,13 +805,13 @@ export declare const expr: {
|
|
|
805
805
|
*/
|
|
806
806
|
dateAdd<T extends DateTime | DateOnly | Time | undefined>(unit: DateUnit, source: ExprUnit<T>, value: ExprInput<number>): ExprUnit<T>;
|
|
807
807
|
/**
|
|
808
|
-
* Date
|
|
808
|
+
* Date format (DATE_FORMAT)
|
|
809
809
|
*
|
|
810
|
-
*
|
|
810
|
+
* Format string rules may differ between DBMS implementations
|
|
811
811
|
*
|
|
812
812
|
* @param source - Date expression
|
|
813
|
-
* @param format -
|
|
814
|
-
* @returns
|
|
813
|
+
* @param format - Format string (e.g., "%Y-%m-%d")
|
|
814
|
+
* @returns Formatted string expression
|
|
815
815
|
*
|
|
816
816
|
* @example
|
|
817
817
|
* ```typescript
|
|
@@ -824,12 +824,12 @@ export declare const expr: {
|
|
|
824
824
|
*/
|
|
825
825
|
formatDate<T extends DateTime | DateOnly | Time | undefined>(source: ExprUnit<T>, format: string): ExprUnit<T extends undefined ? undefined : string>;
|
|
826
826
|
/**
|
|
827
|
-
* NULL
|
|
827
|
+
* NULL replacement (COALESCE/IFNULL)
|
|
828
828
|
*
|
|
829
|
-
*
|
|
829
|
+
* Returns the first non-null value. If the last argument is non-nullable, the result is also non-nullable
|
|
830
830
|
*
|
|
831
|
-
* @param args -
|
|
832
|
-
* @returns
|
|
831
|
+
* @param args - Values to inspect (last is default value)
|
|
832
|
+
* @returns First non-null value
|
|
833
833
|
*
|
|
834
834
|
* @example
|
|
835
835
|
* ```typescript
|
|
@@ -841,18 +841,18 @@ export declare const expr: {
|
|
|
841
841
|
*/
|
|
842
842
|
coalesce: typeof coalesce;
|
|
843
843
|
/**
|
|
844
|
-
*
|
|
844
|
+
* Return NULL if value matches (NULLIF)
|
|
845
845
|
*
|
|
846
|
-
* source === value
|
|
846
|
+
* Returns NULL if source === value, otherwise returns source
|
|
847
847
|
*
|
|
848
|
-
* @param source -
|
|
849
|
-
* @param value -
|
|
850
|
-
* @returns NULL
|
|
848
|
+
* @param source - Original value
|
|
849
|
+
* @param value - Value to compare
|
|
850
|
+
* @returns NULL or original value
|
|
851
851
|
*
|
|
852
852
|
* @example
|
|
853
853
|
* ```typescript
|
|
854
854
|
* db.user().select((u) => ({
|
|
855
|
-
* //
|
|
855
|
+
* // Convert empty string to NULL
|
|
856
856
|
* bio: expr.nullIf(u.bio, ""),
|
|
857
857
|
* }))
|
|
858
858
|
* // SELECT NULLIF(bio, '') AS bio
|
|
@@ -860,11 +860,11 @@ export declare const expr: {
|
|
|
860
860
|
*/
|
|
861
861
|
nullIf<T extends ColumnPrimitive>(source: ExprUnit<T>, value: ExprInput<T>): ExprUnit<T | undefined>;
|
|
862
862
|
/**
|
|
863
|
-
* WHERE
|
|
863
|
+
* Transform WHERE expression to boolean
|
|
864
864
|
*
|
|
865
|
-
*
|
|
865
|
+
* Used when condition results should be used as a boolean column in SELECT clause
|
|
866
866
|
*
|
|
867
|
-
* @param condition -
|
|
867
|
+
* @param condition - Condition to transform
|
|
868
868
|
* @returns boolean expression
|
|
869
869
|
*
|
|
870
870
|
* @example
|
|
@@ -879,7 +879,7 @@ export declare const expr: {
|
|
|
879
879
|
/**
|
|
880
880
|
* CASE WHEN expression builder
|
|
881
881
|
*
|
|
882
|
-
*
|
|
882
|
+
* Build conditional branches using method chaining
|
|
883
883
|
*
|
|
884
884
|
* @returns SwitchExprBuilder instance
|
|
885
885
|
*
|
|
@@ -897,12 +897,12 @@ export declare const expr: {
|
|
|
897
897
|
*/
|
|
898
898
|
switch<T extends ColumnPrimitive>(): SwitchExprBuilder<T>;
|
|
899
899
|
/**
|
|
900
|
-
*
|
|
900
|
+
* Simple IF condition (ternary operator)
|
|
901
901
|
*
|
|
902
902
|
* @param condition - Condition
|
|
903
|
-
* @param then -
|
|
904
|
-
* @param else_ -
|
|
905
|
-
* @returns
|
|
903
|
+
* @param then - Value when condition is true
|
|
904
|
+
* @param else_ - Value when condition is false
|
|
905
|
+
* @returns Conditional value expression
|
|
906
906
|
*
|
|
907
907
|
* @example
|
|
908
908
|
* ```typescript
|
|
@@ -914,18 +914,18 @@ export declare const expr: {
|
|
|
914
914
|
*/
|
|
915
915
|
if<T extends ColumnPrimitive>(condition: WhereExprUnit, then: ExprInput<T>, else_: ExprInput<T>): ExprUnit<T>;
|
|
916
916
|
/**
|
|
917
|
-
*
|
|
917
|
+
* Count rows (COUNT)
|
|
918
918
|
*
|
|
919
|
-
* @param arg -
|
|
920
|
-
* @param distinct - true
|
|
921
|
-
* @returns
|
|
919
|
+
* @param arg - Column to count (all rows if omitted)
|
|
920
|
+
* @param distinct - If true, remove duplicates
|
|
921
|
+
* @returns Row count
|
|
922
922
|
*
|
|
923
923
|
* @example
|
|
924
924
|
* ```typescript
|
|
925
|
-
* //
|
|
925
|
+
* // Total row count
|
|
926
926
|
* db.user().select(() => ({ total: expr.count() }))
|
|
927
927
|
*
|
|
928
|
-
* //
|
|
928
|
+
* // Distinct count
|
|
929
929
|
* db.order().select((o) => ({
|
|
930
930
|
* uniqueCustomers: expr.count(o.customerId, true),
|
|
931
931
|
* }))
|
|
@@ -933,12 +933,12 @@ export declare const expr: {
|
|
|
933
933
|
*/
|
|
934
934
|
count(arg?: ExprUnit<ColumnPrimitive>, distinct?: boolean): ExprUnit<number>;
|
|
935
935
|
/**
|
|
936
|
-
*
|
|
936
|
+
* Sum (SUM)
|
|
937
937
|
*
|
|
938
|
-
* NULL
|
|
938
|
+
* NULL values are ignored. Returns NULL if all values are NULL
|
|
939
939
|
*
|
|
940
|
-
* @param arg -
|
|
941
|
-
* @returns
|
|
940
|
+
* @param arg - Number column to sum
|
|
941
|
+
* @returns Sum (or NULL)
|
|
942
942
|
*
|
|
943
943
|
* @example
|
|
944
944
|
* ```typescript
|
|
@@ -950,12 +950,12 @@ export declare const expr: {
|
|
|
950
950
|
*/
|
|
951
951
|
sum(arg: ExprUnit<number | undefined>): ExprUnit<number | undefined>;
|
|
952
952
|
/**
|
|
953
|
-
*
|
|
953
|
+
* Average (AVG)
|
|
954
954
|
*
|
|
955
|
-
* NULL
|
|
955
|
+
* NULL values are ignored. Returns NULL if all values are NULL
|
|
956
956
|
*
|
|
957
|
-
* @param arg -
|
|
958
|
-
* @returns
|
|
957
|
+
* @param arg - Number column to average
|
|
958
|
+
* @returns Average (or NULL)
|
|
959
959
|
*
|
|
960
960
|
* @example
|
|
961
961
|
* ```typescript
|
|
@@ -967,12 +967,12 @@ export declare const expr: {
|
|
|
967
967
|
*/
|
|
968
968
|
avg(arg: ExprUnit<number | undefined>): ExprUnit<number | undefined>;
|
|
969
969
|
/**
|
|
970
|
-
*
|
|
970
|
+
* Maximum value (MAX)
|
|
971
971
|
*
|
|
972
|
-
* NULL
|
|
972
|
+
* NULL values are ignored. Returns NULL if all values are NULL
|
|
973
973
|
*
|
|
974
|
-
* @param arg -
|
|
975
|
-
* @returns
|
|
974
|
+
* @param arg - Column to find maximum of
|
|
975
|
+
* @returns Maximum value (or NULL)
|
|
976
976
|
*
|
|
977
977
|
* @example
|
|
978
978
|
* ```typescript
|
|
@@ -984,12 +984,12 @@ export declare const expr: {
|
|
|
984
984
|
*/
|
|
985
985
|
max<T extends ColumnPrimitive>(arg: ExprUnit<T>): ExprUnit<T | undefined>;
|
|
986
986
|
/**
|
|
987
|
-
*
|
|
987
|
+
* Minimum value (MIN)
|
|
988
988
|
*
|
|
989
|
-
* NULL
|
|
989
|
+
* NULL values are ignored. Returns NULL if all values are NULL
|
|
990
990
|
*
|
|
991
|
-
* @param arg -
|
|
992
|
-
* @returns
|
|
991
|
+
* @param arg - Column to find minimum of
|
|
992
|
+
* @returns Minimum value (or NULL)
|
|
993
993
|
*
|
|
994
994
|
* @example
|
|
995
995
|
* ```typescript
|
|
@@ -1001,10 +1001,10 @@ export declare const expr: {
|
|
|
1001
1001
|
*/
|
|
1002
1002
|
min<T extends ColumnPrimitive>(arg: ExprUnit<T>): ExprUnit<T | undefined>;
|
|
1003
1003
|
/**
|
|
1004
|
-
*
|
|
1004
|
+
* Greatest value among multiple values (GREATEST)
|
|
1005
1005
|
*
|
|
1006
|
-
* @param args -
|
|
1007
|
-
* @returns
|
|
1006
|
+
* @param args - Values to compare
|
|
1007
|
+
* @returns Greatest value
|
|
1008
1008
|
*
|
|
1009
1009
|
* @example
|
|
1010
1010
|
* ```typescript
|
|
@@ -1016,10 +1016,10 @@ export declare const expr: {
|
|
|
1016
1016
|
*/
|
|
1017
1017
|
greatest<T extends ColumnPrimitive>(...args: ExprInput<T>[]): ExprUnit<T>;
|
|
1018
1018
|
/**
|
|
1019
|
-
*
|
|
1019
|
+
* Least value among multiple values (LEAST)
|
|
1020
1020
|
*
|
|
1021
|
-
* @param args -
|
|
1022
|
-
* @returns
|
|
1021
|
+
* @param args - Values to compare
|
|
1022
|
+
* @returns Least value
|
|
1023
1023
|
*
|
|
1024
1024
|
* @example
|
|
1025
1025
|
* ```typescript
|
|
@@ -1031,9 +1031,9 @@ export declare const expr: {
|
|
|
1031
1031
|
*/
|
|
1032
1032
|
least<T extends ColumnPrimitive>(...args: ExprInput<T>[]): ExprUnit<T>;
|
|
1033
1033
|
/**
|
|
1034
|
-
*
|
|
1034
|
+
* Row number (sequential number for all rows without ROW_NUMBER)
|
|
1035
1035
|
*
|
|
1036
|
-
* @returns
|
|
1036
|
+
* @returns Row number (starting from 1)
|
|
1037
1037
|
*
|
|
1038
1038
|
* @example
|
|
1039
1039
|
* ```typescript
|
|
@@ -1045,15 +1045,15 @@ export declare const expr: {
|
|
|
1045
1045
|
*/
|
|
1046
1046
|
rowNum(): ExprUnit<number>;
|
|
1047
1047
|
/**
|
|
1048
|
-
*
|
|
1048
|
+
* Generate random number (RAND/RANDOM)
|
|
1049
1049
|
*
|
|
1050
|
-
* 0
|
|
1050
|
+
* Returns a random number between 0 and 1. Mainly used for random ordering in ORDER BY
|
|
1051
1051
|
*
|
|
1052
|
-
* @returns 0
|
|
1052
|
+
* @returns Random number between 0 and 1
|
|
1053
1053
|
*
|
|
1054
1054
|
* @example
|
|
1055
1055
|
* ```typescript
|
|
1056
|
-
* //
|
|
1056
|
+
* // Random sorting
|
|
1057
1057
|
* db.user().orderBy(() => expr.random()).limit(10)
|
|
1058
1058
|
* ```
|
|
1059
1059
|
*/
|
|
@@ -1061,9 +1061,9 @@ export declare const expr: {
|
|
|
1061
1061
|
/**
|
|
1062
1062
|
* type transformation (CAST)
|
|
1063
1063
|
*
|
|
1064
|
-
* @param source -
|
|
1065
|
-
* @param targetType -
|
|
1066
|
-
* @returns
|
|
1064
|
+
* @param source - Expression to transform
|
|
1065
|
+
* @param targetType - Target data type
|
|
1066
|
+
* @returns Transformed expression
|
|
1067
1067
|
*
|
|
1068
1068
|
* @example
|
|
1069
1069
|
* ```typescript
|
|
@@ -1075,12 +1075,12 @@ export declare const expr: {
|
|
|
1075
1075
|
*/
|
|
1076
1076
|
cast<T extends ColumnPrimitive, TDataType extends DataType>(source: ExprUnit<T>, targetType: TDataType): ExprUnit<T extends undefined ? undefined : InferColumnPrimitiveFromDataType<TDataType>>;
|
|
1077
1077
|
/**
|
|
1078
|
-
*
|
|
1078
|
+
* Scalar Subquery - Subquery that returns a single value in SELECT clause
|
|
1079
1079
|
*
|
|
1080
|
-
*
|
|
1080
|
+
* The subquery must return exactly one row and one column
|
|
1081
1081
|
*
|
|
1082
1082
|
* @param dataType - Data type of the returned value
|
|
1083
|
-
* @param queryable -
|
|
1083
|
+
* @param queryable - Queryable that returns a scalar value
|
|
1084
1084
|
* @returns Subquery result expression
|
|
1085
1085
|
*
|
|
1086
1086
|
* @example
|
|
@@ -1101,12 +1101,12 @@ export declare const expr: {
|
|
|
1101
1101
|
getSelectQueryDef(): SelectQueryDef;
|
|
1102
1102
|
}): ExprUnit<ColumnPrimitiveMap[TStr] | undefined>;
|
|
1103
1103
|
/**
|
|
1104
|
-
* ROW_NUMBER() -
|
|
1104
|
+
* ROW_NUMBER() - Row number within a partition
|
|
1105
1105
|
*
|
|
1106
|
-
*
|
|
1106
|
+
* Assigns sequential numbers starting from 1 within each partition
|
|
1107
1107
|
*
|
|
1108
1108
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1109
|
-
* @returns
|
|
1109
|
+
* @returns Row number (starting from 1)
|
|
1110
1110
|
*
|
|
1111
1111
|
* @example
|
|
1112
1112
|
* ```typescript
|
|
@@ -1122,10 +1122,10 @@ export declare const expr: {
|
|
|
1122
1122
|
*/
|
|
1123
1123
|
rowNumber(spec: WinSpecInput): ExprUnit<number>;
|
|
1124
1124
|
/**
|
|
1125
|
-
* RANK() -
|
|
1125
|
+
* RANK() - Rank within a partition (ties get same rank, next rank is skipped)
|
|
1126
1126
|
*
|
|
1127
1127
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1128
|
-
* @returns
|
|
1128
|
+
* @returns Rank (skips after ties: 1, 1, 3)
|
|
1129
1129
|
*
|
|
1130
1130
|
* @example
|
|
1131
1131
|
* ```typescript
|
|
@@ -1139,10 +1139,10 @@ export declare const expr: {
|
|
|
1139
1139
|
*/
|
|
1140
1140
|
rank(spec: WinSpecInput): ExprUnit<number>;
|
|
1141
1141
|
/**
|
|
1142
|
-
* DENSE_RANK() -
|
|
1142
|
+
* DENSE_RANK() - Dense rank within a partition (ties get same rank, next rank is consecutive)
|
|
1143
1143
|
*
|
|
1144
1144
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1145
|
-
* @returns
|
|
1145
|
+
* @returns Dense rank (consecutive after ties: 1, 1, 2)
|
|
1146
1146
|
*
|
|
1147
1147
|
* @example
|
|
1148
1148
|
* ```typescript
|
|
@@ -1156,15 +1156,15 @@ export declare const expr: {
|
|
|
1156
1156
|
*/
|
|
1157
1157
|
denseRank(spec: WinSpecInput): ExprUnit<number>;
|
|
1158
1158
|
/**
|
|
1159
|
-
* NTILE(n) -
|
|
1159
|
+
* NTILE(n) - Split partition into n groups
|
|
1160
1160
|
*
|
|
1161
|
-
* @param n -
|
|
1161
|
+
* @param n - Number of groups to split into
|
|
1162
1162
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1163
|
-
* @returns
|
|
1163
|
+
* @returns Group number (1 ~ n)
|
|
1164
1164
|
*
|
|
1165
1165
|
* @example
|
|
1166
1166
|
* ```typescript
|
|
1167
|
-
* //
|
|
1167
|
+
* // Quartile split to find top 25%
|
|
1168
1168
|
* db.user().select((u) => ({
|
|
1169
1169
|
* name: u.name,
|
|
1170
1170
|
* quartile: expr.ntile(4, {
|
|
@@ -1175,12 +1175,12 @@ export declare const expr: {
|
|
|
1175
1175
|
*/
|
|
1176
1176
|
ntile(n: number, spec: WinSpecInput): ExprUnit<number>;
|
|
1177
1177
|
/**
|
|
1178
|
-
* LAG() -
|
|
1178
|
+
* LAG() - Reference value from a previous row
|
|
1179
1179
|
*
|
|
1180
|
-
* @param column -
|
|
1180
|
+
* @param column - Column to reference
|
|
1181
1181
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1182
|
-
* @param options - offset (
|
|
1183
|
-
* @returns
|
|
1182
|
+
* @param options - offset (default 1), default (default value when no previous row)
|
|
1183
|
+
* @returns Previous row's value (or default value/NULL)
|
|
1184
1184
|
*
|
|
1185
1185
|
* @example
|
|
1186
1186
|
* ```typescript
|
|
@@ -1199,12 +1199,12 @@ export declare const expr: {
|
|
|
1199
1199
|
default?: ExprInput<T>;
|
|
1200
1200
|
}): ExprUnit<T | undefined>;
|
|
1201
1201
|
/**
|
|
1202
|
-
* LEAD() -
|
|
1202
|
+
* LEAD() - Reference value from a following row
|
|
1203
1203
|
*
|
|
1204
|
-
* @param column -
|
|
1204
|
+
* @param column - Column to reference
|
|
1205
1205
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1206
|
-
* @param options - offset (
|
|
1207
|
-
* @returns
|
|
1206
|
+
* @param options - offset (default 1), default (default value when no following row)
|
|
1207
|
+
* @returns Following row's value (or default value/NULL)
|
|
1208
1208
|
*
|
|
1209
1209
|
* @example
|
|
1210
1210
|
* ```typescript
|
|
@@ -1223,11 +1223,11 @@ export declare const expr: {
|
|
|
1223
1223
|
default?: ExprInput<T>;
|
|
1224
1224
|
}): ExprUnit<T | undefined>;
|
|
1225
1225
|
/**
|
|
1226
|
-
* FIRST_VALUE() -
|
|
1226
|
+
* FIRST_VALUE() - First value in the partition/frame
|
|
1227
1227
|
*
|
|
1228
|
-
* @param column -
|
|
1228
|
+
* @param column - Column to reference
|
|
1229
1229
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1230
|
-
* @returns
|
|
1230
|
+
* @returns First value
|
|
1231
1231
|
*
|
|
1232
1232
|
* @example
|
|
1233
1233
|
* ```typescript
|
|
@@ -1242,11 +1242,11 @@ export declare const expr: {
|
|
|
1242
1242
|
*/
|
|
1243
1243
|
firstValue<T extends ColumnPrimitive>(column: ExprUnit<T>, spec: WinSpecInput): ExprUnit<T | undefined>;
|
|
1244
1244
|
/**
|
|
1245
|
-
* LAST_VALUE() -
|
|
1245
|
+
* LAST_VALUE() - Last value in the partition/frame
|
|
1246
1246
|
*
|
|
1247
|
-
* @param column -
|
|
1247
|
+
* @param column - Column to reference
|
|
1248
1248
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1249
|
-
* @returns
|
|
1249
|
+
* @returns Last value
|
|
1250
1250
|
*
|
|
1251
1251
|
* @example
|
|
1252
1252
|
* ```typescript
|
|
@@ -1261,15 +1261,15 @@ export declare const expr: {
|
|
|
1261
1261
|
*/
|
|
1262
1262
|
lastValue<T extends ColumnPrimitive>(column: ExprUnit<T>, spec: WinSpecInput): ExprUnit<T | undefined>;
|
|
1263
1263
|
/**
|
|
1264
|
-
* SUM() OVER - Window
|
|
1264
|
+
* SUM() OVER - Window sum
|
|
1265
1265
|
*
|
|
1266
|
-
* @param column -
|
|
1266
|
+
* @param column - Column to sum
|
|
1267
1267
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1268
|
-
* @returns
|
|
1268
|
+
* @returns Sum within window
|
|
1269
1269
|
*
|
|
1270
1270
|
* @example
|
|
1271
1271
|
* ```typescript
|
|
1272
|
-
* //
|
|
1272
|
+
* // Running total
|
|
1273
1273
|
* db.order().select((o) => ({
|
|
1274
1274
|
* ...o,
|
|
1275
1275
|
* runningTotal: expr.sumOver(o.amount, {
|
|
@@ -1281,15 +1281,15 @@ export declare const expr: {
|
|
|
1281
1281
|
*/
|
|
1282
1282
|
sumOver(column: ExprUnit<number | undefined>, spec: WinSpecInput): ExprUnit<number | undefined>;
|
|
1283
1283
|
/**
|
|
1284
|
-
* AVG() OVER - Window
|
|
1284
|
+
* AVG() OVER - Window average
|
|
1285
1285
|
*
|
|
1286
|
-
* @param column -
|
|
1286
|
+
* @param column - Column to average
|
|
1287
1287
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1288
|
-
* @returns
|
|
1288
|
+
* @returns Average within window
|
|
1289
1289
|
*
|
|
1290
1290
|
* @example
|
|
1291
1291
|
* ```typescript
|
|
1292
|
-
* //
|
|
1292
|
+
* // Moving average
|
|
1293
1293
|
* db.stock().select((s) => ({
|
|
1294
1294
|
* ...s,
|
|
1295
1295
|
* movingAvg: expr.avgOver(s.price, {
|
|
@@ -1301,11 +1301,11 @@ export declare const expr: {
|
|
|
1301
1301
|
*/
|
|
1302
1302
|
avgOver(column: ExprUnit<number | undefined>, spec: WinSpecInput): ExprUnit<number | undefined>;
|
|
1303
1303
|
/**
|
|
1304
|
-
* COUNT() OVER - Window
|
|
1304
|
+
* COUNT() OVER - Window count
|
|
1305
1305
|
*
|
|
1306
1306
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1307
|
-
* @param column -
|
|
1308
|
-
* @returns
|
|
1307
|
+
* @param column - Column to count (all rows if omitted)
|
|
1308
|
+
* @returns Row count within window
|
|
1309
1309
|
*
|
|
1310
1310
|
* @example
|
|
1311
1311
|
* ```typescript
|
|
@@ -1319,11 +1319,11 @@ export declare const expr: {
|
|
|
1319
1319
|
*/
|
|
1320
1320
|
countOver(spec: WinSpecInput, column?: ExprUnit<ColumnPrimitive>): ExprUnit<number>;
|
|
1321
1321
|
/**
|
|
1322
|
-
* MIN() OVER - Window
|
|
1322
|
+
* MIN() OVER - Window minimum
|
|
1323
1323
|
*
|
|
1324
|
-
* @param column -
|
|
1324
|
+
* @param column - Column to find minimum of
|
|
1325
1325
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1326
|
-
* @returns
|
|
1326
|
+
* @returns Minimum value within window
|
|
1327
1327
|
*
|
|
1328
1328
|
* @example
|
|
1329
1329
|
* ```typescript
|
|
@@ -1337,11 +1337,11 @@ export declare const expr: {
|
|
|
1337
1337
|
*/
|
|
1338
1338
|
minOver<T extends ColumnPrimitive>(column: ExprUnit<T>, spec: WinSpecInput): ExprUnit<T | undefined>;
|
|
1339
1339
|
/**
|
|
1340
|
-
* MAX() OVER - Window
|
|
1340
|
+
* MAX() OVER - Window maximum
|
|
1341
1341
|
*
|
|
1342
|
-
* @param column -
|
|
1342
|
+
* @param column - Column to find maximum of
|
|
1343
1343
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1344
|
-
* @returns
|
|
1344
|
+
* @returns Maximum value within window
|
|
1345
1345
|
*
|
|
1346
1346
|
* @example
|
|
1347
1347
|
* ```typescript
|
|
@@ -1355,9 +1355,9 @@ export declare const expr: {
|
|
|
1355
1355
|
*/
|
|
1356
1356
|
maxOver<T extends ColumnPrimitive>(column: ExprUnit<T>, spec: WinSpecInput): ExprUnit<T | undefined>;
|
|
1357
1357
|
/**
|
|
1358
|
-
* ExprInput
|
|
1358
|
+
* Transform ExprInput to Expr (internal use)
|
|
1359
1359
|
*
|
|
1360
|
-
* @param value -
|
|
1360
|
+
* @param value - Value to transform
|
|
1361
1361
|
* @returns Expr JSON AST
|
|
1362
1362
|
*/
|
|
1363
1363
|
toExpr(value: ExprInput<ColumnPrimitive>): Expr;
|