@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.js
CHANGED
|
@@ -11,9 +11,9 @@ const expr = {
|
|
|
11
11
|
*
|
|
12
12
|
* Widen to base type matching dataType, remove literal type
|
|
13
13
|
*
|
|
14
|
-
* @param dataType -
|
|
15
|
-
* @param value -
|
|
16
|
-
* @returns
|
|
14
|
+
* @param dataType - The data type of the value ("string", "number", "boolean", "DateTime", "DateOnly", "Time", "Uuid", "Buffer")
|
|
15
|
+
* @param value - Value to wrap (undefined allowed)
|
|
16
|
+
* @returns Wrapped ExprUnit instance
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```typescript
|
|
@@ -191,16 +191,16 @@ const expr = {
|
|
|
191
191
|
/**
|
|
192
192
|
* range comparison (BETWEEN)
|
|
193
193
|
*
|
|
194
|
-
* from/to
|
|
194
|
+
* If from/to is undefined, that direction is unbounded
|
|
195
195
|
*
|
|
196
196
|
* @param source - Column or expression to compare
|
|
197
|
-
* @param from -
|
|
198
|
-
* @param to -
|
|
197
|
+
* @param from - Start value (no lower bound if undefined)
|
|
198
|
+
* @param to - End value (no upper bound if undefined)
|
|
199
199
|
* @returns WHERE condition expression
|
|
200
200
|
*
|
|
201
201
|
* @example
|
|
202
202
|
* ```typescript
|
|
203
|
-
* // range
|
|
203
|
+
* // Specify range
|
|
204
204
|
* db.user().where((u) => [expr.between(u.age, 18, 65)])
|
|
205
205
|
* // WHERE age BETWEEN 18 AND 65
|
|
206
206
|
*
|
|
@@ -220,9 +220,9 @@ const expr = {
|
|
|
220
220
|
//#endregion
|
|
221
221
|
//#region ========== WHERE - NULL check ==========
|
|
222
222
|
/**
|
|
223
|
-
* NULL
|
|
223
|
+
* NULL check (IS NULL)
|
|
224
224
|
*
|
|
225
|
-
* @param source -
|
|
225
|
+
* @param source - Column or expression to check
|
|
226
226
|
* @returns WHERE condition expression
|
|
227
227
|
*
|
|
228
228
|
* @example
|
|
@@ -240,22 +240,22 @@ const expr = {
|
|
|
240
240
|
//#endregion
|
|
241
241
|
//#region ========== WHERE - String search ==========
|
|
242
242
|
/**
|
|
243
|
-
* LIKE pattern
|
|
243
|
+
* LIKE pattern matching
|
|
244
244
|
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
245
|
+
* `%` matches zero or more characters, `_` matches a single character.
|
|
246
|
+
* Special characters are escaped with `\`
|
|
247
247
|
*
|
|
248
|
-
* @param source -
|
|
249
|
-
* @param pattern -
|
|
248
|
+
* @param source - Column or expression to search
|
|
249
|
+
* @param pattern - Search pattern (%, _ wildcards available)
|
|
250
250
|
* @returns WHERE condition expression
|
|
251
251
|
*
|
|
252
252
|
* @example
|
|
253
253
|
* ```typescript
|
|
254
|
-
* //
|
|
254
|
+
* // Prefix search
|
|
255
255
|
* db.user().where((u) => [expr.like(u.name, "John%")])
|
|
256
256
|
* // WHERE name LIKE 'John%' ESCAPE '\'
|
|
257
257
|
*
|
|
258
|
-
* //
|
|
258
|
+
* // Contains search
|
|
259
259
|
* db.user().where((u) => [expr.like(u.email, "%@gmail.com")])
|
|
260
260
|
* ```
|
|
261
261
|
*/
|
|
@@ -267,12 +267,12 @@ const expr = {
|
|
|
267
267
|
});
|
|
268
268
|
},
|
|
269
269
|
/**
|
|
270
|
-
*
|
|
270
|
+
* Regular expression pattern matching
|
|
271
271
|
*
|
|
272
|
-
*
|
|
272
|
+
* Note: regex syntax may differ between DBMS implementations
|
|
273
273
|
*
|
|
274
|
-
* @param source -
|
|
275
|
-
* @param pattern -
|
|
274
|
+
* @param source - Column or expression to search
|
|
275
|
+
* @param pattern - Regular expression pattern
|
|
276
276
|
* @returns WHERE condition expression
|
|
277
277
|
*
|
|
278
278
|
* @example
|
|
@@ -291,10 +291,10 @@ const expr = {
|
|
|
291
291
|
//#endregion
|
|
292
292
|
//#region ========== WHERE - IN ==========
|
|
293
293
|
/**
|
|
294
|
-
* IN operator -
|
|
294
|
+
* IN operator - Compare against a list of values
|
|
295
295
|
*
|
|
296
296
|
* @param source - Column or expression to compare
|
|
297
|
-
* @param values -
|
|
297
|
+
* @param values - List of values to compare against
|
|
298
298
|
* @returns WHERE condition expression
|
|
299
299
|
*
|
|
300
300
|
* @example
|
|
@@ -311,14 +311,14 @@ const expr = {
|
|
|
311
311
|
});
|
|
312
312
|
},
|
|
313
313
|
/**
|
|
314
|
-
* IN (SELECT ...) -
|
|
314
|
+
* IN (SELECT ...) - Compare against subquery results
|
|
315
315
|
*
|
|
316
|
-
*
|
|
316
|
+
* The subquery must SELECT only a single column
|
|
317
317
|
*
|
|
318
318
|
* @param source - Column or expression to compare
|
|
319
|
-
* @param query -
|
|
319
|
+
* @param query - Queryable that returns a single column
|
|
320
320
|
* @returns WHERE condition expression
|
|
321
|
-
* @throws {Error}
|
|
321
|
+
* @throws {Error} When the subquery does not return a single column
|
|
322
322
|
*
|
|
323
323
|
* @example
|
|
324
324
|
* ```typescript
|
|
@@ -345,16 +345,16 @@ const expr = {
|
|
|
345
345
|
});
|
|
346
346
|
},
|
|
347
347
|
/**
|
|
348
|
-
* EXISTS (SELECT ...) -
|
|
348
|
+
* EXISTS (SELECT ...) - Check if subquery returns any rows
|
|
349
349
|
*
|
|
350
|
-
*
|
|
350
|
+
* Returns true if the subquery returns one or more rows
|
|
351
351
|
*
|
|
352
|
-
* @param query -
|
|
352
|
+
* @param query - Queryable to check for existence
|
|
353
353
|
* @returns WHERE condition expression
|
|
354
354
|
*
|
|
355
355
|
* @example
|
|
356
356
|
* ```typescript
|
|
357
|
-
* //
|
|
357
|
+
* // Query users who have orders
|
|
358
358
|
* db.user().where((u) => [
|
|
359
359
|
* expr.exists(
|
|
360
360
|
* db.order().where((o) => [expr.eq(o.userId, u.id)])
|
|
@@ -373,10 +373,10 @@ const expr = {
|
|
|
373
373
|
//#endregion
|
|
374
374
|
//#region ========== WHERE - Logical operators ==========
|
|
375
375
|
/**
|
|
376
|
-
* NOT operator -
|
|
376
|
+
* NOT operator - Negate a condition
|
|
377
377
|
*
|
|
378
|
-
* @param arg -
|
|
379
|
-
* @returns
|
|
378
|
+
* @param arg - Condition to negate
|
|
379
|
+
* @returns Negated WHERE condition expression
|
|
380
380
|
*
|
|
381
381
|
* @example
|
|
382
382
|
* ```typescript
|
|
@@ -391,12 +391,12 @@ const expr = {
|
|
|
391
391
|
});
|
|
392
392
|
},
|
|
393
393
|
/**
|
|
394
|
-
* AND operator -
|
|
394
|
+
* AND operator - All conditions must be satisfied
|
|
395
395
|
*
|
|
396
|
-
*
|
|
396
|
+
* Combines multiple conditions with AND. Passing an array to where() automatically applies AND
|
|
397
397
|
*
|
|
398
|
-
* @param conditions -
|
|
399
|
-
* @returns
|
|
398
|
+
* @param conditions - List of conditions to combine with AND
|
|
399
|
+
* @returns Combined WHERE condition expression
|
|
400
400
|
*
|
|
401
401
|
* @example
|
|
402
402
|
* ```typescript
|
|
@@ -419,10 +419,10 @@ const expr = {
|
|
|
419
419
|
});
|
|
420
420
|
},
|
|
421
421
|
/**
|
|
422
|
-
* OR operator -
|
|
422
|
+
* OR operator - At least one condition must be satisfied
|
|
423
423
|
*
|
|
424
|
-
* @param conditions -
|
|
425
|
-
* @returns
|
|
424
|
+
* @param conditions - List of conditions to combine with OR
|
|
425
|
+
* @returns Combined WHERE condition expression
|
|
426
426
|
*
|
|
427
427
|
* @example
|
|
428
428
|
* ```typescript
|
|
@@ -445,14 +445,14 @@ const expr = {
|
|
|
445
445
|
});
|
|
446
446
|
},
|
|
447
447
|
//#endregion
|
|
448
|
-
//#region ========== SELECT -
|
|
448
|
+
//#region ========== SELECT - String ==========
|
|
449
449
|
/**
|
|
450
|
-
*
|
|
450
|
+
* String concatenation (CONCAT)
|
|
451
451
|
*
|
|
452
|
-
* NULL
|
|
452
|
+
* NULL values are treated as empty strings (auto-transformed per DBMS)
|
|
453
453
|
*
|
|
454
|
-
* @param args -
|
|
455
|
-
* @returns
|
|
454
|
+
* @param args - Strings to concatenate
|
|
455
|
+
* @returns Concatenated string expression
|
|
456
456
|
*
|
|
457
457
|
* @example
|
|
458
458
|
* ```typescript
|
|
@@ -469,11 +469,11 @@ const expr = {
|
|
|
469
469
|
});
|
|
470
470
|
},
|
|
471
471
|
/**
|
|
472
|
-
*
|
|
472
|
+
* Extract specified length from the left of a string (LEFT)
|
|
473
473
|
*
|
|
474
|
-
* @param source -
|
|
475
|
-
* @param length -
|
|
476
|
-
* @returns
|
|
474
|
+
* @param source - Original string
|
|
475
|
+
* @param length - Number of characters to extract
|
|
476
|
+
* @returns Extracted string expression
|
|
477
477
|
*
|
|
478
478
|
* @example
|
|
479
479
|
* ```typescript
|
|
@@ -491,11 +491,11 @@ const expr = {
|
|
|
491
491
|
});
|
|
492
492
|
},
|
|
493
493
|
/**
|
|
494
|
-
*
|
|
494
|
+
* Extract specified length from the right of a string (RIGHT)
|
|
495
495
|
*
|
|
496
|
-
* @param source -
|
|
497
|
-
* @param length -
|
|
498
|
-
* @returns
|
|
496
|
+
* @param source - Original string
|
|
497
|
+
* @param length - Number of characters to extract
|
|
498
|
+
* @returns Extracted string expression
|
|
499
499
|
*
|
|
500
500
|
* @example
|
|
501
501
|
* ```typescript
|
|
@@ -513,10 +513,10 @@ const expr = {
|
|
|
513
513
|
});
|
|
514
514
|
},
|
|
515
515
|
/**
|
|
516
|
-
*
|
|
516
|
+
* Remove whitespace from both sides of a string (TRIM)
|
|
517
517
|
*
|
|
518
|
-
* @param source -
|
|
519
|
-
* @returns
|
|
518
|
+
* @param source - Original string
|
|
519
|
+
* @returns String expression with whitespace removed
|
|
520
520
|
*
|
|
521
521
|
* @example
|
|
522
522
|
* ```typescript
|
|
@@ -533,14 +533,14 @@ const expr = {
|
|
|
533
533
|
});
|
|
534
534
|
},
|
|
535
535
|
/**
|
|
536
|
-
*
|
|
536
|
+
* Left padding (LPAD)
|
|
537
537
|
*
|
|
538
|
-
*
|
|
538
|
+
* Repeatedly adds fillString on the left until the target length is reached
|
|
539
539
|
*
|
|
540
|
-
* @param source -
|
|
541
|
-
* @param length -
|
|
542
|
-
* @param fillString -
|
|
543
|
-
* @returns
|
|
540
|
+
* @param source - Original string
|
|
541
|
+
* @param length - Target length
|
|
542
|
+
* @param fillString - String to use for padding
|
|
543
|
+
* @returns Padded string expression
|
|
544
544
|
*
|
|
545
545
|
* @example
|
|
546
546
|
* ```typescript
|
|
@@ -560,12 +560,12 @@ const expr = {
|
|
|
560
560
|
});
|
|
561
561
|
},
|
|
562
562
|
/**
|
|
563
|
-
*
|
|
563
|
+
* String replacement (REPLACE)
|
|
564
564
|
*
|
|
565
|
-
* @param source -
|
|
566
|
-
* @param from -
|
|
567
|
-
* @param to -
|
|
568
|
-
* @returns
|
|
565
|
+
* @param source - Original string
|
|
566
|
+
* @param from - String to find
|
|
567
|
+
* @param to - Replacement string
|
|
568
|
+
* @returns Replaced string expression
|
|
569
569
|
*
|
|
570
570
|
* @example
|
|
571
571
|
* ```typescript
|
|
@@ -584,10 +584,10 @@ const expr = {
|
|
|
584
584
|
});
|
|
585
585
|
},
|
|
586
586
|
/**
|
|
587
|
-
*
|
|
587
|
+
* Convert string to uppercase (UPPER)
|
|
588
588
|
*
|
|
589
|
-
* @param source -
|
|
590
|
-
* @returns
|
|
589
|
+
* @param source - Original string
|
|
590
|
+
* @returns Uppercase string expression
|
|
591
591
|
*
|
|
592
592
|
* @example
|
|
593
593
|
* ```typescript
|
|
@@ -604,10 +604,10 @@ const expr = {
|
|
|
604
604
|
});
|
|
605
605
|
},
|
|
606
606
|
/**
|
|
607
|
-
*
|
|
607
|
+
* Convert string to lowercase (LOWER)
|
|
608
608
|
*
|
|
609
|
-
* @param source -
|
|
610
|
-
* @returns
|
|
609
|
+
* @param source - Original string
|
|
610
|
+
* @returns Lowercase string expression
|
|
611
611
|
*
|
|
612
612
|
* @example
|
|
613
613
|
* ```typescript
|
|
@@ -624,10 +624,10 @@ const expr = {
|
|
|
624
624
|
});
|
|
625
625
|
},
|
|
626
626
|
/**
|
|
627
|
-
*
|
|
627
|
+
* String length (character count)
|
|
628
628
|
*
|
|
629
|
-
* @param source -
|
|
630
|
-
* @returns
|
|
629
|
+
* @param source - Original string
|
|
630
|
+
* @returns Character count
|
|
631
631
|
*
|
|
632
632
|
* @example
|
|
633
633
|
* ```typescript
|
|
@@ -644,12 +644,12 @@ const expr = {
|
|
|
644
644
|
});
|
|
645
645
|
},
|
|
646
646
|
/**
|
|
647
|
-
*
|
|
647
|
+
* String byte length
|
|
648
648
|
*
|
|
649
|
-
* UTF-8
|
|
649
|
+
* In UTF-8, CJK characters are 3 bytes each
|
|
650
650
|
*
|
|
651
|
-
* @param source -
|
|
652
|
-
* @returns
|
|
651
|
+
* @param source - Original string
|
|
652
|
+
* @returns Byte count
|
|
653
653
|
*
|
|
654
654
|
* @example
|
|
655
655
|
* ```typescript
|
|
@@ -666,19 +666,19 @@ const expr = {
|
|
|
666
666
|
});
|
|
667
667
|
},
|
|
668
668
|
/**
|
|
669
|
-
*
|
|
669
|
+
* Extract part of a string (SUBSTRING)
|
|
670
670
|
*
|
|
671
|
-
*
|
|
671
|
+
* Uses 1-based index per SQL standard
|
|
672
672
|
*
|
|
673
|
-
* @param source -
|
|
674
|
-
* @param start -
|
|
675
|
-
* @param length -
|
|
676
|
-
* @returns
|
|
673
|
+
* @param source - Original string
|
|
674
|
+
* @param start - Start position (starting from 1)
|
|
675
|
+
* @param length - Length to extract (to the end if omitted)
|
|
676
|
+
* @returns Extracted string expression
|
|
677
677
|
*
|
|
678
678
|
* @example
|
|
679
679
|
* ```typescript
|
|
680
680
|
* db.user().select((u) => ({
|
|
681
|
-
* // "Hello World"
|
|
681
|
+
* // From "Hello World", 5 characters starting at index 1: "Hello"
|
|
682
682
|
* prefix: expr.substring(u.name, 1, 5),
|
|
683
683
|
* }))
|
|
684
684
|
* // SELECT SUBSTRING(name, 1, 5) AS prefix
|
|
@@ -693,13 +693,13 @@ const expr = {
|
|
|
693
693
|
});
|
|
694
694
|
},
|
|
695
695
|
/**
|
|
696
|
-
*
|
|
696
|
+
* Find position within a string (LOCATE/CHARINDEX)
|
|
697
697
|
*
|
|
698
|
-
* 1-based index
|
|
698
|
+
* Returns 1-based index, or 0 if not found
|
|
699
699
|
*
|
|
700
|
-
* @param source -
|
|
701
|
-
* @param search -
|
|
702
|
-
* @returns
|
|
700
|
+
* @param source - String to search in
|
|
701
|
+
* @param search - String to find
|
|
702
|
+
* @returns Position (starting from 1, 0 if not found)
|
|
703
703
|
*
|
|
704
704
|
* @example
|
|
705
705
|
* ```typescript
|
|
@@ -720,10 +720,10 @@ const expr = {
|
|
|
720
720
|
//#endregion
|
|
721
721
|
//#region ========== SELECT - Number ==========
|
|
722
722
|
/**
|
|
723
|
-
*
|
|
723
|
+
* Absolute value (ABS)
|
|
724
724
|
*
|
|
725
|
-
* @param source -
|
|
726
|
-
* @returns
|
|
725
|
+
* @param source - Original number
|
|
726
|
+
* @returns Absolute value expression
|
|
727
727
|
*
|
|
728
728
|
* @example
|
|
729
729
|
* ```typescript
|
|
@@ -740,11 +740,11 @@ const expr = {
|
|
|
740
740
|
});
|
|
741
741
|
},
|
|
742
742
|
/**
|
|
743
|
-
*
|
|
743
|
+
* Round (ROUND)
|
|
744
744
|
*
|
|
745
|
-
* @param source -
|
|
746
|
-
* @param digits -
|
|
747
|
-
* @returns
|
|
745
|
+
* @param source - Original number
|
|
746
|
+
* @param digits - Number of decimal places
|
|
747
|
+
* @returns Rounded number expression
|
|
748
748
|
*
|
|
749
749
|
* @example
|
|
750
750
|
* ```typescript
|
|
@@ -763,10 +763,10 @@ const expr = {
|
|
|
763
763
|
});
|
|
764
764
|
},
|
|
765
765
|
/**
|
|
766
|
-
*
|
|
766
|
+
* Ceiling (CEILING)
|
|
767
767
|
*
|
|
768
|
-
* @param source -
|
|
769
|
-
* @returns
|
|
768
|
+
* @param source - Original number
|
|
769
|
+
* @returns Ceiling number expression
|
|
770
770
|
*
|
|
771
771
|
* @example
|
|
772
772
|
* ```typescript
|
|
@@ -784,10 +784,10 @@ const expr = {
|
|
|
784
784
|
});
|
|
785
785
|
},
|
|
786
786
|
/**
|
|
787
|
-
*
|
|
787
|
+
* Floor (FLOOR)
|
|
788
788
|
*
|
|
789
|
-
* @param source -
|
|
790
|
-
* @returns
|
|
789
|
+
* @param source - Original number
|
|
790
|
+
* @returns Floor number expression
|
|
791
791
|
*
|
|
792
792
|
* @example
|
|
793
793
|
* ```typescript
|
|
@@ -807,10 +807,10 @@ const expr = {
|
|
|
807
807
|
//#endregion
|
|
808
808
|
//#region ========== SELECT - Date ==========
|
|
809
809
|
/**
|
|
810
|
-
*
|
|
810
|
+
* Extract year (YEAR)
|
|
811
811
|
*
|
|
812
|
-
* @param source - DateTime
|
|
813
|
-
* @returns
|
|
812
|
+
* @param source - DateTime or DateOnly expression
|
|
813
|
+
* @returns Year (4-digit number)
|
|
814
814
|
*
|
|
815
815
|
* @example
|
|
816
816
|
* ```typescript
|
|
@@ -827,10 +827,10 @@ const expr = {
|
|
|
827
827
|
});
|
|
828
828
|
},
|
|
829
829
|
/**
|
|
830
|
-
*
|
|
830
|
+
* Extract month (MONTH)
|
|
831
831
|
*
|
|
832
|
-
* @param source - DateTime
|
|
833
|
-
* @returns
|
|
832
|
+
* @param source - DateTime or DateOnly expression
|
|
833
|
+
* @returns Month (1~12)
|
|
834
834
|
*
|
|
835
835
|
* @example
|
|
836
836
|
* ```typescript
|
|
@@ -847,10 +847,10 @@ const expr = {
|
|
|
847
847
|
});
|
|
848
848
|
},
|
|
849
849
|
/**
|
|
850
|
-
*
|
|
850
|
+
* Extract day (DAY)
|
|
851
851
|
*
|
|
852
|
-
* @param source - DateTime
|
|
853
|
-
* @returns
|
|
852
|
+
* @param source - DateTime or DateOnly expression
|
|
853
|
+
* @returns Day (1~31)
|
|
854
854
|
*
|
|
855
855
|
* @example
|
|
856
856
|
* ```typescript
|
|
@@ -867,10 +867,10 @@ const expr = {
|
|
|
867
867
|
});
|
|
868
868
|
},
|
|
869
869
|
/**
|
|
870
|
-
*
|
|
870
|
+
* Extract hour (HOUR)
|
|
871
871
|
*
|
|
872
|
-
* @param source - DateTime
|
|
873
|
-
* @returns
|
|
872
|
+
* @param source - DateTime or Time expression
|
|
873
|
+
* @returns Hour (0~23)
|
|
874
874
|
*
|
|
875
875
|
* @example
|
|
876
876
|
* ```typescript
|
|
@@ -887,10 +887,10 @@ const expr = {
|
|
|
887
887
|
});
|
|
888
888
|
},
|
|
889
889
|
/**
|
|
890
|
-
*
|
|
890
|
+
* Extract minute (MINUTE)
|
|
891
891
|
*
|
|
892
|
-
* @param source - DateTime
|
|
893
|
-
* @returns
|
|
892
|
+
* @param source - DateTime or Time expression
|
|
893
|
+
* @returns Minute (0~59)
|
|
894
894
|
*
|
|
895
895
|
* @example
|
|
896
896
|
* ```typescript
|
|
@@ -907,10 +907,10 @@ const expr = {
|
|
|
907
907
|
});
|
|
908
908
|
},
|
|
909
909
|
/**
|
|
910
|
-
*
|
|
910
|
+
* Extract second (SECOND)
|
|
911
911
|
*
|
|
912
|
-
* @param source - DateTime
|
|
913
|
-
* @returns
|
|
912
|
+
* @param source - DateTime or Time expression
|
|
913
|
+
* @returns Second (0~59)
|
|
914
914
|
*
|
|
915
915
|
* @example
|
|
916
916
|
* ```typescript
|
|
@@ -927,12 +927,12 @@ const expr = {
|
|
|
927
927
|
});
|
|
928
928
|
},
|
|
929
929
|
/**
|
|
930
|
-
* ISO
|
|
930
|
+
* Extract ISO week number
|
|
931
931
|
*
|
|
932
|
-
* ISO 8601
|
|
932
|
+
* ISO 8601 week number (starts Monday, 1~53)
|
|
933
933
|
*
|
|
934
934
|
* @param source - DateOnly expression
|
|
935
|
-
* @returns ISO
|
|
935
|
+
* @returns ISO week number
|
|
936
936
|
*
|
|
937
937
|
* @example
|
|
938
938
|
* ```typescript
|
|
@@ -949,19 +949,19 @@ const expr = {
|
|
|
949
949
|
});
|
|
950
950
|
},
|
|
951
951
|
/**
|
|
952
|
-
* ISO
|
|
952
|
+
* ISO week start date (Monday)
|
|
953
953
|
*
|
|
954
|
-
*
|
|
954
|
+
* Returns the Monday of the week the given date belongs to
|
|
955
955
|
*
|
|
956
956
|
* @param source - DateOnly expression
|
|
957
|
-
* @returns
|
|
957
|
+
* @returns Week start date (Monday)
|
|
958
958
|
*
|
|
959
959
|
* @example
|
|
960
960
|
* ```typescript
|
|
961
961
|
* db.order().select((o) => ({
|
|
962
962
|
* weekStart: expr.isoWeekStartDate(o.orderDate),
|
|
963
963
|
* }))
|
|
964
|
-
* // 2024-01-10 (
|
|
964
|
+
* // 2024-01-10 (Wed) → 2024-01-08 (Mon)
|
|
965
965
|
* ```
|
|
966
966
|
*/
|
|
967
967
|
isoWeekStartDate(source) {
|
|
@@ -971,12 +971,12 @@ const expr = {
|
|
|
971
971
|
});
|
|
972
972
|
},
|
|
973
973
|
/**
|
|
974
|
-
* ISO
|
|
974
|
+
* ISO year-month (first day of the month)
|
|
975
975
|
*
|
|
976
|
-
*
|
|
976
|
+
* Returns the first day of the month for the given date
|
|
977
977
|
*
|
|
978
978
|
* @param source - DateOnly expression
|
|
979
|
-
* @returns
|
|
979
|
+
* @returns First day of the month
|
|
980
980
|
*
|
|
981
981
|
* @example
|
|
982
982
|
* ```typescript
|
|
@@ -993,12 +993,12 @@ const expr = {
|
|
|
993
993
|
});
|
|
994
994
|
},
|
|
995
995
|
/**
|
|
996
|
-
*
|
|
996
|
+
* Calculate date difference (DATEDIFF)
|
|
997
997
|
*
|
|
998
|
-
* @param unit -
|
|
999
|
-
* @param from -
|
|
1000
|
-
* @param to -
|
|
1001
|
-
* @returns
|
|
998
|
+
* @param unit - Unit ("year", "month", "day", "hour", "minute", "second")
|
|
999
|
+
* @param from - Start date
|
|
1000
|
+
* @param to - End date
|
|
1001
|
+
* @returns Difference value (to - from)
|
|
1002
1002
|
*
|
|
1003
1003
|
* @example
|
|
1004
1004
|
* ```typescript
|
|
@@ -1017,12 +1017,12 @@ const expr = {
|
|
|
1017
1017
|
});
|
|
1018
1018
|
},
|
|
1019
1019
|
/**
|
|
1020
|
-
*
|
|
1020
|
+
* Add to date (DATEADD)
|
|
1021
1021
|
*
|
|
1022
|
-
* @param unit -
|
|
1023
|
-
* @param source -
|
|
1024
|
-
* @param value -
|
|
1025
|
-
* @returns
|
|
1022
|
+
* @param unit - Unit ("year", "month", "day", "hour", "minute", "second")
|
|
1023
|
+
* @param source - Original date
|
|
1024
|
+
* @param value - Value to add (negative allowed)
|
|
1025
|
+
* @returns Calculated date
|
|
1026
1026
|
*
|
|
1027
1027
|
* @example
|
|
1028
1028
|
* ```typescript
|
|
@@ -1041,13 +1041,13 @@ const expr = {
|
|
|
1041
1041
|
});
|
|
1042
1042
|
},
|
|
1043
1043
|
/**
|
|
1044
|
-
* Date
|
|
1044
|
+
* Date format (DATE_FORMAT)
|
|
1045
1045
|
*
|
|
1046
|
-
*
|
|
1046
|
+
* Format string rules may differ between DBMS implementations
|
|
1047
1047
|
*
|
|
1048
1048
|
* @param source - Date expression
|
|
1049
|
-
* @param format -
|
|
1050
|
-
* @returns
|
|
1049
|
+
* @param format - Format string (e.g., "%Y-%m-%d")
|
|
1050
|
+
* @returns Formatted string expression
|
|
1051
1051
|
*
|
|
1052
1052
|
* @example
|
|
1053
1053
|
* ```typescript
|
|
@@ -1068,12 +1068,12 @@ const expr = {
|
|
|
1068
1068
|
//#endregion
|
|
1069
1069
|
//#region ========== SELECT - Condition ==========
|
|
1070
1070
|
/**
|
|
1071
|
-
* NULL
|
|
1071
|
+
* NULL replacement (COALESCE/IFNULL)
|
|
1072
1072
|
*
|
|
1073
|
-
*
|
|
1073
|
+
* Returns the first non-null value. If the last argument is non-nullable, the result is also non-nullable
|
|
1074
1074
|
*
|
|
1075
|
-
* @param args -
|
|
1076
|
-
* @returns
|
|
1075
|
+
* @param args - Values to inspect (last is default value)
|
|
1076
|
+
* @returns First non-null value
|
|
1077
1077
|
*
|
|
1078
1078
|
* @example
|
|
1079
1079
|
* ```typescript
|
|
@@ -1085,18 +1085,18 @@ const expr = {
|
|
|
1085
1085
|
*/
|
|
1086
1086
|
coalesce,
|
|
1087
1087
|
/**
|
|
1088
|
-
*
|
|
1088
|
+
* Return NULL if value matches (NULLIF)
|
|
1089
1089
|
*
|
|
1090
|
-
* source === value
|
|
1090
|
+
* Returns NULL if source === value, otherwise returns source
|
|
1091
1091
|
*
|
|
1092
|
-
* @param source -
|
|
1093
|
-
* @param value -
|
|
1094
|
-
* @returns NULL
|
|
1092
|
+
* @param source - Original value
|
|
1093
|
+
* @param value - Value to compare
|
|
1094
|
+
* @returns NULL or original value
|
|
1095
1095
|
*
|
|
1096
1096
|
* @example
|
|
1097
1097
|
* ```typescript
|
|
1098
1098
|
* db.user().select((u) => ({
|
|
1099
|
-
* //
|
|
1099
|
+
* // Convert empty string to NULL
|
|
1100
1100
|
* bio: expr.nullIf(u.bio, ""),
|
|
1101
1101
|
* }))
|
|
1102
1102
|
* // SELECT NULLIF(bio, '') AS bio
|
|
@@ -1110,11 +1110,11 @@ const expr = {
|
|
|
1110
1110
|
});
|
|
1111
1111
|
},
|
|
1112
1112
|
/**
|
|
1113
|
-
* WHERE
|
|
1113
|
+
* Transform WHERE expression to boolean
|
|
1114
1114
|
*
|
|
1115
|
-
*
|
|
1115
|
+
* Used when condition results should be used as a boolean column in SELECT clause
|
|
1116
1116
|
*
|
|
1117
|
-
* @param condition -
|
|
1117
|
+
* @param condition - Condition to transform
|
|
1118
1118
|
* @returns boolean expression
|
|
1119
1119
|
*
|
|
1120
1120
|
* @example
|
|
@@ -1134,7 +1134,7 @@ const expr = {
|
|
|
1134
1134
|
/**
|
|
1135
1135
|
* CASE WHEN expression builder
|
|
1136
1136
|
*
|
|
1137
|
-
*
|
|
1137
|
+
* Build conditional branches using method chaining
|
|
1138
1138
|
*
|
|
1139
1139
|
* @returns SwitchExprBuilder instance
|
|
1140
1140
|
*
|
|
@@ -1154,12 +1154,12 @@ const expr = {
|
|
|
1154
1154
|
return createSwitchBuilder();
|
|
1155
1155
|
},
|
|
1156
1156
|
/**
|
|
1157
|
-
*
|
|
1157
|
+
* Simple IF condition (ternary operator)
|
|
1158
1158
|
*
|
|
1159
1159
|
* @param condition - Condition
|
|
1160
|
-
* @param then -
|
|
1161
|
-
* @param else_ -
|
|
1162
|
-
* @returns
|
|
1160
|
+
* @param then - Value when condition is true
|
|
1161
|
+
* @param else_ - Value when condition is false
|
|
1162
|
+
* @returns Conditional value expression
|
|
1163
1163
|
*
|
|
1164
1164
|
* @example
|
|
1165
1165
|
* ```typescript
|
|
@@ -1193,20 +1193,20 @@ const expr = {
|
|
|
1193
1193
|
},
|
|
1194
1194
|
//#endregion
|
|
1195
1195
|
//#region ========== SELECT - Aggregate ==========
|
|
1196
|
-
// SUM, AVG, MAX
|
|
1196
|
+
// Aggregates like SUM, AVG, MAX return NULL only when all values are NULL or no rows exist (rows with NULL values are ignored)
|
|
1197
1197
|
/**
|
|
1198
|
-
*
|
|
1198
|
+
* Count rows (COUNT)
|
|
1199
1199
|
*
|
|
1200
|
-
* @param arg -
|
|
1201
|
-
* @param distinct - true
|
|
1202
|
-
* @returns
|
|
1200
|
+
* @param arg - Column to count (all rows if omitted)
|
|
1201
|
+
* @param distinct - If true, remove duplicates
|
|
1202
|
+
* @returns Row count
|
|
1203
1203
|
*
|
|
1204
1204
|
* @example
|
|
1205
1205
|
* ```typescript
|
|
1206
|
-
* //
|
|
1206
|
+
* // Total row count
|
|
1207
1207
|
* db.user().select(() => ({ total: expr.count() }))
|
|
1208
1208
|
*
|
|
1209
|
-
* //
|
|
1209
|
+
* // Distinct count
|
|
1210
1210
|
* db.order().select((o) => ({
|
|
1211
1211
|
* uniqueCustomers: expr.count(o.customerId, true),
|
|
1212
1212
|
* }))
|
|
@@ -1220,12 +1220,12 @@ const expr = {
|
|
|
1220
1220
|
});
|
|
1221
1221
|
},
|
|
1222
1222
|
/**
|
|
1223
|
-
*
|
|
1223
|
+
* Sum (SUM)
|
|
1224
1224
|
*
|
|
1225
|
-
* NULL
|
|
1225
|
+
* NULL values are ignored. Returns NULL if all values are NULL
|
|
1226
1226
|
*
|
|
1227
|
-
* @param arg -
|
|
1228
|
-
* @returns
|
|
1227
|
+
* @param arg - Number column to sum
|
|
1228
|
+
* @returns Sum (or NULL)
|
|
1229
1229
|
*
|
|
1230
1230
|
* @example
|
|
1231
1231
|
* ```typescript
|
|
@@ -1242,12 +1242,12 @@ const expr = {
|
|
|
1242
1242
|
});
|
|
1243
1243
|
},
|
|
1244
1244
|
/**
|
|
1245
|
-
*
|
|
1245
|
+
* Average (AVG)
|
|
1246
1246
|
*
|
|
1247
|
-
* NULL
|
|
1247
|
+
* NULL values are ignored. Returns NULL if all values are NULL
|
|
1248
1248
|
*
|
|
1249
|
-
* @param arg -
|
|
1250
|
-
* @returns
|
|
1249
|
+
* @param arg - Number column to average
|
|
1250
|
+
* @returns Average (or NULL)
|
|
1251
1251
|
*
|
|
1252
1252
|
* @example
|
|
1253
1253
|
* ```typescript
|
|
@@ -1264,12 +1264,12 @@ const expr = {
|
|
|
1264
1264
|
});
|
|
1265
1265
|
},
|
|
1266
1266
|
/**
|
|
1267
|
-
*
|
|
1267
|
+
* Maximum value (MAX)
|
|
1268
1268
|
*
|
|
1269
|
-
* NULL
|
|
1269
|
+
* NULL values are ignored. Returns NULL if all values are NULL
|
|
1270
1270
|
*
|
|
1271
|
-
* @param arg -
|
|
1272
|
-
* @returns
|
|
1271
|
+
* @param arg - Column to find maximum of
|
|
1272
|
+
* @returns Maximum value (or NULL)
|
|
1273
1273
|
*
|
|
1274
1274
|
* @example
|
|
1275
1275
|
* ```typescript
|
|
@@ -1286,12 +1286,12 @@ const expr = {
|
|
|
1286
1286
|
});
|
|
1287
1287
|
},
|
|
1288
1288
|
/**
|
|
1289
|
-
*
|
|
1289
|
+
* Minimum value (MIN)
|
|
1290
1290
|
*
|
|
1291
|
-
* NULL
|
|
1291
|
+
* NULL values are ignored. Returns NULL if all values are NULL
|
|
1292
1292
|
*
|
|
1293
|
-
* @param arg -
|
|
1294
|
-
* @returns
|
|
1293
|
+
* @param arg - Column to find minimum of
|
|
1294
|
+
* @returns Minimum value (or NULL)
|
|
1295
1295
|
*
|
|
1296
1296
|
* @example
|
|
1297
1297
|
* ```typescript
|
|
@@ -1310,10 +1310,10 @@ const expr = {
|
|
|
1310
1310
|
//#endregion
|
|
1311
1311
|
//#region ========== SELECT - Other ==========
|
|
1312
1312
|
/**
|
|
1313
|
-
*
|
|
1313
|
+
* Greatest value among multiple values (GREATEST)
|
|
1314
1314
|
*
|
|
1315
|
-
* @param args -
|
|
1316
|
-
* @returns
|
|
1315
|
+
* @param args - Values to compare
|
|
1316
|
+
* @returns Greatest value
|
|
1317
1317
|
*
|
|
1318
1318
|
* @example
|
|
1319
1319
|
* ```typescript
|
|
@@ -1330,10 +1330,10 @@ const expr = {
|
|
|
1330
1330
|
});
|
|
1331
1331
|
},
|
|
1332
1332
|
/**
|
|
1333
|
-
*
|
|
1333
|
+
* Least value among multiple values (LEAST)
|
|
1334
1334
|
*
|
|
1335
|
-
* @param args -
|
|
1336
|
-
* @returns
|
|
1335
|
+
* @param args - Values to compare
|
|
1336
|
+
* @returns Least value
|
|
1337
1337
|
*
|
|
1338
1338
|
* @example
|
|
1339
1339
|
* ```typescript
|
|
@@ -1350,9 +1350,9 @@ const expr = {
|
|
|
1350
1350
|
});
|
|
1351
1351
|
},
|
|
1352
1352
|
/**
|
|
1353
|
-
*
|
|
1353
|
+
* Row number (sequential number for all rows without ROW_NUMBER)
|
|
1354
1354
|
*
|
|
1355
|
-
* @returns
|
|
1355
|
+
* @returns Row number (starting from 1)
|
|
1356
1356
|
*
|
|
1357
1357
|
* @example
|
|
1358
1358
|
* ```typescript
|
|
@@ -1368,15 +1368,15 @@ const expr = {
|
|
|
1368
1368
|
});
|
|
1369
1369
|
},
|
|
1370
1370
|
/**
|
|
1371
|
-
*
|
|
1371
|
+
* Generate random number (RAND/RANDOM)
|
|
1372
1372
|
*
|
|
1373
|
-
* 0
|
|
1373
|
+
* Returns a random number between 0 and 1. Mainly used for random ordering in ORDER BY
|
|
1374
1374
|
*
|
|
1375
|
-
* @returns 0
|
|
1375
|
+
* @returns Random number between 0 and 1
|
|
1376
1376
|
*
|
|
1377
1377
|
* @example
|
|
1378
1378
|
* ```typescript
|
|
1379
|
-
* //
|
|
1379
|
+
* // Random sorting
|
|
1380
1380
|
* db.user().orderBy(() => expr.random()).limit(10)
|
|
1381
1381
|
* ```
|
|
1382
1382
|
*/
|
|
@@ -1388,9 +1388,9 @@ const expr = {
|
|
|
1388
1388
|
/**
|
|
1389
1389
|
* type transformation (CAST)
|
|
1390
1390
|
*
|
|
1391
|
-
* @param source -
|
|
1392
|
-
* @param targetType -
|
|
1393
|
-
* @returns
|
|
1391
|
+
* @param source - Expression to transform
|
|
1392
|
+
* @param targetType - Target data type
|
|
1393
|
+
* @returns Transformed expression
|
|
1394
1394
|
*
|
|
1395
1395
|
* @example
|
|
1396
1396
|
* ```typescript
|
|
@@ -1408,12 +1408,12 @@ const expr = {
|
|
|
1408
1408
|
});
|
|
1409
1409
|
},
|
|
1410
1410
|
/**
|
|
1411
|
-
*
|
|
1411
|
+
* Scalar Subquery - Subquery that returns a single value in SELECT clause
|
|
1412
1412
|
*
|
|
1413
|
-
*
|
|
1413
|
+
* The subquery must return exactly one row and one column
|
|
1414
1414
|
*
|
|
1415
1415
|
* @param dataType - Data type of the returned value
|
|
1416
|
-
* @param queryable -
|
|
1416
|
+
* @param queryable - Queryable that returns a scalar value
|
|
1417
1417
|
* @returns Subquery result expression
|
|
1418
1418
|
*
|
|
1419
1419
|
* @example
|
|
@@ -1439,12 +1439,12 @@ const expr = {
|
|
|
1439
1439
|
//#endregion
|
|
1440
1440
|
//#region ========== SELECT - Window Functions ==========
|
|
1441
1441
|
/**
|
|
1442
|
-
* ROW_NUMBER() -
|
|
1442
|
+
* ROW_NUMBER() - Row number within a partition
|
|
1443
1443
|
*
|
|
1444
|
-
*
|
|
1444
|
+
* Assigns sequential numbers starting from 1 within each partition
|
|
1445
1445
|
*
|
|
1446
1446
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1447
|
-
* @returns
|
|
1447
|
+
* @returns Row number (starting from 1)
|
|
1448
1448
|
*
|
|
1449
1449
|
* @example
|
|
1450
1450
|
* ```typescript
|
|
@@ -1466,10 +1466,10 @@ const expr = {
|
|
|
1466
1466
|
});
|
|
1467
1467
|
},
|
|
1468
1468
|
/**
|
|
1469
|
-
* RANK() -
|
|
1469
|
+
* RANK() - Rank within a partition (ties get same rank, next rank is skipped)
|
|
1470
1470
|
*
|
|
1471
1471
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1472
|
-
* @returns
|
|
1472
|
+
* @returns Rank (skips after ties: 1, 1, 3)
|
|
1473
1473
|
*
|
|
1474
1474
|
* @example
|
|
1475
1475
|
* ```typescript
|
|
@@ -1489,10 +1489,10 @@ const expr = {
|
|
|
1489
1489
|
});
|
|
1490
1490
|
},
|
|
1491
1491
|
/**
|
|
1492
|
-
* DENSE_RANK() -
|
|
1492
|
+
* DENSE_RANK() - Dense rank within a partition (ties get same rank, next rank is consecutive)
|
|
1493
1493
|
*
|
|
1494
1494
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1495
|
-
* @returns
|
|
1495
|
+
* @returns Dense rank (consecutive after ties: 1, 1, 2)
|
|
1496
1496
|
*
|
|
1497
1497
|
* @example
|
|
1498
1498
|
* ```typescript
|
|
@@ -1512,15 +1512,15 @@ const expr = {
|
|
|
1512
1512
|
});
|
|
1513
1513
|
},
|
|
1514
1514
|
/**
|
|
1515
|
-
* NTILE(n) -
|
|
1515
|
+
* NTILE(n) - Split partition into n groups
|
|
1516
1516
|
*
|
|
1517
|
-
* @param n -
|
|
1517
|
+
* @param n - Number of groups to split into
|
|
1518
1518
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1519
|
-
* @returns
|
|
1519
|
+
* @returns Group number (1 ~ n)
|
|
1520
1520
|
*
|
|
1521
1521
|
* @example
|
|
1522
1522
|
* ```typescript
|
|
1523
|
-
* //
|
|
1523
|
+
* // Quartile split to find top 25%
|
|
1524
1524
|
* db.user().select((u) => ({
|
|
1525
1525
|
* name: u.name,
|
|
1526
1526
|
* quartile: expr.ntile(4, {
|
|
@@ -1537,12 +1537,12 @@ const expr = {
|
|
|
1537
1537
|
});
|
|
1538
1538
|
},
|
|
1539
1539
|
/**
|
|
1540
|
-
* LAG() -
|
|
1540
|
+
* LAG() - Reference value from a previous row
|
|
1541
1541
|
*
|
|
1542
|
-
* @param column -
|
|
1542
|
+
* @param column - Column to reference
|
|
1543
1543
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1544
|
-
* @param options - offset (
|
|
1545
|
-
* @returns
|
|
1544
|
+
* @param options - offset (default 1), default (default value when no previous row)
|
|
1545
|
+
* @returns Previous row's value (or default value/NULL)
|
|
1546
1546
|
*
|
|
1547
1547
|
* @example
|
|
1548
1548
|
* ```typescript
|
|
@@ -1569,12 +1569,12 @@ const expr = {
|
|
|
1569
1569
|
});
|
|
1570
1570
|
},
|
|
1571
1571
|
/**
|
|
1572
|
-
* LEAD() -
|
|
1572
|
+
* LEAD() - Reference value from a following row
|
|
1573
1573
|
*
|
|
1574
|
-
* @param column -
|
|
1574
|
+
* @param column - Column to reference
|
|
1575
1575
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1576
|
-
* @param options - offset (
|
|
1577
|
-
* @returns
|
|
1576
|
+
* @param options - offset (default 1), default (default value when no following row)
|
|
1577
|
+
* @returns Following row's value (or default value/NULL)
|
|
1578
1578
|
*
|
|
1579
1579
|
* @example
|
|
1580
1580
|
* ```typescript
|
|
@@ -1601,11 +1601,11 @@ const expr = {
|
|
|
1601
1601
|
});
|
|
1602
1602
|
},
|
|
1603
1603
|
/**
|
|
1604
|
-
* FIRST_VALUE() -
|
|
1604
|
+
* FIRST_VALUE() - First value in the partition/frame
|
|
1605
1605
|
*
|
|
1606
|
-
* @param column -
|
|
1606
|
+
* @param column - Column to reference
|
|
1607
1607
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1608
|
-
* @returns
|
|
1608
|
+
* @returns First value
|
|
1609
1609
|
*
|
|
1610
1610
|
* @example
|
|
1611
1611
|
* ```typescript
|
|
@@ -1626,11 +1626,11 @@ const expr = {
|
|
|
1626
1626
|
});
|
|
1627
1627
|
},
|
|
1628
1628
|
/**
|
|
1629
|
-
* LAST_VALUE() -
|
|
1629
|
+
* LAST_VALUE() - Last value in the partition/frame
|
|
1630
1630
|
*
|
|
1631
|
-
* @param column -
|
|
1631
|
+
* @param column - Column to reference
|
|
1632
1632
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1633
|
-
* @returns
|
|
1633
|
+
* @returns Last value
|
|
1634
1634
|
*
|
|
1635
1635
|
* @example
|
|
1636
1636
|
* ```typescript
|
|
@@ -1651,15 +1651,15 @@ const expr = {
|
|
|
1651
1651
|
});
|
|
1652
1652
|
},
|
|
1653
1653
|
/**
|
|
1654
|
-
* SUM() OVER - Window
|
|
1654
|
+
* SUM() OVER - Window sum
|
|
1655
1655
|
*
|
|
1656
|
-
* @param column -
|
|
1656
|
+
* @param column - Column to sum
|
|
1657
1657
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1658
|
-
* @returns
|
|
1658
|
+
* @returns Sum within window
|
|
1659
1659
|
*
|
|
1660
1660
|
* @example
|
|
1661
1661
|
* ```typescript
|
|
1662
|
-
* //
|
|
1662
|
+
* // Running total
|
|
1663
1663
|
* db.order().select((o) => ({
|
|
1664
1664
|
* ...o,
|
|
1665
1665
|
* runningTotal: expr.sumOver(o.amount, {
|
|
@@ -1677,15 +1677,15 @@ const expr = {
|
|
|
1677
1677
|
});
|
|
1678
1678
|
},
|
|
1679
1679
|
/**
|
|
1680
|
-
* AVG() OVER - Window
|
|
1680
|
+
* AVG() OVER - Window average
|
|
1681
1681
|
*
|
|
1682
|
-
* @param column -
|
|
1682
|
+
* @param column - Column to average
|
|
1683
1683
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1684
|
-
* @returns
|
|
1684
|
+
* @returns Average within window
|
|
1685
1685
|
*
|
|
1686
1686
|
* @example
|
|
1687
1687
|
* ```typescript
|
|
1688
|
-
* //
|
|
1688
|
+
* // Moving average
|
|
1689
1689
|
* db.stock().select((s) => ({
|
|
1690
1690
|
* ...s,
|
|
1691
1691
|
* movingAvg: expr.avgOver(s.price, {
|
|
@@ -1703,11 +1703,11 @@ const expr = {
|
|
|
1703
1703
|
});
|
|
1704
1704
|
},
|
|
1705
1705
|
/**
|
|
1706
|
-
* COUNT() OVER - Window
|
|
1706
|
+
* COUNT() OVER - Window count
|
|
1707
1707
|
*
|
|
1708
1708
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1709
|
-
* @param column -
|
|
1710
|
-
* @returns
|
|
1709
|
+
* @param column - Column to count (all rows if omitted)
|
|
1710
|
+
* @returns Row count within window
|
|
1711
1711
|
*
|
|
1712
1712
|
* @example
|
|
1713
1713
|
* ```typescript
|
|
@@ -1727,11 +1727,11 @@ const expr = {
|
|
|
1727
1727
|
});
|
|
1728
1728
|
},
|
|
1729
1729
|
/**
|
|
1730
|
-
* MIN() OVER - Window
|
|
1730
|
+
* MIN() OVER - Window minimum
|
|
1731
1731
|
*
|
|
1732
|
-
* @param column -
|
|
1732
|
+
* @param column - Column to find minimum of
|
|
1733
1733
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1734
|
-
* @returns
|
|
1734
|
+
* @returns Minimum value within window
|
|
1735
1735
|
*
|
|
1736
1736
|
* @example
|
|
1737
1737
|
* ```typescript
|
|
@@ -1751,11 +1751,11 @@ const expr = {
|
|
|
1751
1751
|
});
|
|
1752
1752
|
},
|
|
1753
1753
|
/**
|
|
1754
|
-
* MAX() OVER - Window
|
|
1754
|
+
* MAX() OVER - Window maximum
|
|
1755
1755
|
*
|
|
1756
|
-
* @param column -
|
|
1756
|
+
* @param column - Column to find maximum of
|
|
1757
1757
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1758
|
-
* @returns
|
|
1758
|
+
* @returns Maximum value within window
|
|
1759
1759
|
*
|
|
1760
1760
|
* @example
|
|
1761
1761
|
* ```typescript
|
|
@@ -1777,9 +1777,9 @@ const expr = {
|
|
|
1777
1777
|
//#endregion
|
|
1778
1778
|
//#region ========== Helper ==========
|
|
1779
1779
|
/**
|
|
1780
|
-
* ExprInput
|
|
1780
|
+
* Transform ExprInput to Expr (internal use)
|
|
1781
1781
|
*
|
|
1782
|
-
* @param value -
|
|
1782
|
+
* @param value - Value to transform
|
|
1783
1783
|
* @returns Expr JSON AST
|
|
1784
1784
|
*/
|
|
1785
1785
|
toExpr(value) {
|