@simplysm/orm-common 14.0.99 → 14.0.101
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/db-context.d.ts +0 -17
- package/dist/db-context.d.ts.map +1 -1
- package/dist/db-context.js +0 -17
- package/dist/db-context.js.map +1 -1
- package/dist/errors/db-transaction-error.d.ts +0 -15
- package/dist/errors/db-transaction-error.d.ts.map +1 -1
- package/dist/errors/db-transaction-error.js +0 -15
- package/dist/errors/db-transaction-error.js.map +1 -1
- package/dist/exec/executable.d.ts +0 -24
- package/dist/exec/executable.d.ts.map +1 -1
- package/dist/exec/executable.js +0 -24
- package/dist/exec/executable.js.map +1 -1
- package/dist/exec/queryable.d.ts +0 -300
- package/dist/exec/queryable.d.ts.map +1 -1
- package/dist/exec/queryable.js +0 -213
- package/dist/exec/queryable.js.map +1 -1
- package/dist/expr/expr.d.ts +0 -689
- package/dist/expr/expr.d.ts.map +1 -1
- package/dist/expr/expr.js +0 -689
- package/dist/expr/expr.js.map +1 -1
- package/dist/schema/factory/column-builder.d.ts +0 -86
- package/dist/schema/factory/column-builder.d.ts.map +1 -1
- package/dist/schema/factory/column-builder.js +0 -74
- package/dist/schema/factory/column-builder.js.map +1 -1
- package/dist/schema/factory/index-builder.d.ts +0 -60
- package/dist/schema/factory/index-builder.d.ts.map +1 -1
- package/dist/schema/factory/index-builder.js +0 -60
- package/dist/schema/factory/index-builder.js.map +1 -1
- package/dist/schema/factory/relation-builder.d.ts +0 -83
- package/dist/schema/factory/relation-builder.d.ts.map +1 -1
- package/dist/schema/factory/relation-builder.js +0 -77
- package/dist/schema/factory/relation-builder.js.map +1 -1
- package/dist/schema/procedure-builder.d.ts +0 -87
- package/dist/schema/procedure-builder.d.ts.map +1 -1
- package/dist/schema/procedure-builder.js +0 -87
- package/dist/schema/procedure-builder.js.map +1 -1
- package/dist/schema/table-builder.d.ts +0 -127
- package/dist/schema/table-builder.d.ts.map +1 -1
- package/dist/schema/table-builder.js +0 -127
- package/dist/schema/table-builder.js.map +1 -1
- package/dist/schema/view-builder.d.ts +0 -76
- package/dist/schema/view-builder.d.ts.map +1 -1
- package/dist/schema/view-builder.js +0 -76
- package/dist/schema/view-builder.js.map +1 -1
- package/dist/types/column.d.ts +0 -38
- package/dist/types/column.d.ts.map +1 -1
- package/dist/types/column.js +0 -13
- package/dist/types/column.js.map +1 -1
- package/dist/types/db.d.ts +0 -54
- package/dist/types/db.d.ts.map +1 -1
- package/dist/types/db.js +0 -8
- package/dist/types/db.js.map +1 -1
- package/dist/utils/result-parser.d.ts +0 -21
- package/dist/utils/result-parser.d.ts.map +1 -1
- package/dist/utils/result-parser.js +0 -24
- package/dist/utils/result-parser.js.map +1 -1
- package/package.json +2 -2
- package/src/db-context.ts +0 -17
- package/src/errors/db-transaction-error.ts +0 -15
- package/src/exec/executable.ts +0 -24
- package/src/exec/queryable.ts +0 -300
- package/src/expr/expr.ts +0 -689
- package/src/schema/factory/column-builder.ts +0 -86
- package/src/schema/factory/index-builder.ts +0 -60
- package/src/schema/factory/relation-builder.ts +0 -83
- package/src/schema/procedure-builder.ts +0 -87
- package/src/schema/table-builder.ts +0 -127
- package/src/schema/view-builder.ts +0 -76
- package/src/types/column.ts +0 -38
- package/src/types/db.ts +0 -54
- package/src/utils/result-parser.ts +0 -24
package/dist/expr/expr.js
CHANGED
|
@@ -7,27 +7,6 @@ import { ExprUnit, WhereExprUnit } from "./expr-unit.js";
|
|
|
7
7
|
* SQL 문자열 대신 JSON AST(Expr)를 생성하며, QueryBuilder가
|
|
8
8
|
* 각 DBMS(MySQL, MSSQL, PostgreSQL)로 변환
|
|
9
9
|
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* // WHERE condition
|
|
13
|
-
* db.user().where((u) => [
|
|
14
|
-
* expr.eq(u.status, "active"),
|
|
15
|
-
* expr.gt(u.age, 18),
|
|
16
|
-
* ])
|
|
17
|
-
*
|
|
18
|
-
* // SELECT expression
|
|
19
|
-
* db.user().select((u) => ({
|
|
20
|
-
* name: expr.concat(u.firstName, " ", u.lastName),
|
|
21
|
-
* age: expr.dateDiff("year", u.birthDate, expr.val("DateOnly", DateOnly.today())),
|
|
22
|
-
* }))
|
|
23
|
-
*
|
|
24
|
-
* // Aggregate function
|
|
25
|
-
* db.order().groupBy((o) => o.userId).select((o) => ({
|
|
26
|
-
* userId: o.userId,
|
|
27
|
-
* total: expr.sum(o.amount),
|
|
28
|
-
* }))
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
10
|
* @see {@link Queryable} Query builder 클래스
|
|
32
11
|
* @see {@link ExprUnit} Expression 래퍼 클래스
|
|
33
12
|
*/
|
|
@@ -41,21 +20,6 @@ export const expr = {
|
|
|
41
20
|
* @param dataType - 값의 데이터 타입 ("string", "number", "boolean", "DateTime", "DateOnly", "Time", "Uuid", "Buffer")
|
|
42
21
|
* @param value - 래핑할 값 (undefined 허용)
|
|
43
22
|
* @returns 래핑된 ExprUnit 인스턴스
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```typescript
|
|
47
|
-
* // String value
|
|
48
|
-
* expr.val("string", "active")
|
|
49
|
-
*
|
|
50
|
-
* // Number value
|
|
51
|
-
* expr.val("number", 100)
|
|
52
|
-
*
|
|
53
|
-
* // Date value
|
|
54
|
-
* expr.val("DateOnly", DateOnly.today())
|
|
55
|
-
*
|
|
56
|
-
* // undefined value
|
|
57
|
-
* expr.val("string", undefined)
|
|
58
|
-
* ```
|
|
59
23
|
*/
|
|
60
24
|
val(dataType, value) {
|
|
61
25
|
return new ExprUnit(dataType, { type: "value", value });
|
|
@@ -68,12 +32,6 @@ export const expr = {
|
|
|
68
32
|
* @param dataType - Column 데이터 타입
|
|
69
33
|
* @param path - Column 경로 (테이블 별칭, column 이름 등)
|
|
70
34
|
* @returns Column 참조 ExprUnit 인스턴스
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```typescript
|
|
74
|
-
* // Direct column reference (internal use)
|
|
75
|
-
* expr.col("string", "T1", "name")
|
|
76
|
-
* ```
|
|
77
35
|
*/
|
|
78
36
|
col(dataType, ...path) {
|
|
79
37
|
return new ExprUnit(dataType, { type: "column", path });
|
|
@@ -86,18 +44,6 @@ export const expr = {
|
|
|
86
44
|
*
|
|
87
45
|
* @param dataType - 반환 값의 데이터 타입
|
|
88
46
|
* @returns 태그드 템플릿 함수
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* // Using MySQL JSON function
|
|
93
|
-
* db.user().select((u) => ({
|
|
94
|
-
* name: u.name,
|
|
95
|
-
* data: expr.raw("string")`JSON_EXTRACT(${u.metadata}, '$.email')`,
|
|
96
|
-
* }))
|
|
97
|
-
*
|
|
98
|
-
* // PostgreSQL array function
|
|
99
|
-
* expr.raw("number")`ARRAY_LENGTH(${u.tags}, 1)`
|
|
100
|
-
* ```
|
|
101
47
|
*/
|
|
102
48
|
raw(dataType) {
|
|
103
49
|
return (strings, ...values) => {
|
|
@@ -121,12 +67,6 @@ export const expr = {
|
|
|
121
67
|
* @param source - 비교할 column 또는 expression
|
|
122
68
|
* @param target - 비교 대상 값 또는 expression
|
|
123
69
|
* @returns WHERE 조건 expression
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* db.user().where((u) => [expr.eq(u.status, "active")])
|
|
128
|
-
* // WHERE status <=> 'active' (MySQL)
|
|
129
|
-
* ```
|
|
130
70
|
*/
|
|
131
71
|
eq(source, target) {
|
|
132
72
|
return new WhereExprUnit({
|
|
@@ -141,12 +81,6 @@ export const expr = {
|
|
|
141
81
|
* @param source - 비교할 column 또는 expression
|
|
142
82
|
* @param target - 비교 대상 값 또는 expression
|
|
143
83
|
* @returns WHERE 조건 expression
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* ```typescript
|
|
147
|
-
* db.user().where((u) => [expr.gt(u.age, 18)])
|
|
148
|
-
* // WHERE age > 18
|
|
149
|
-
* ```
|
|
150
84
|
*/
|
|
151
85
|
gt(source, target) {
|
|
152
86
|
return new WhereExprUnit({
|
|
@@ -161,12 +95,6 @@ export const expr = {
|
|
|
161
95
|
* @param source - 비교할 column 또는 expression
|
|
162
96
|
* @param target - 비교 대상 값 또는 expression
|
|
163
97
|
* @returns WHERE 조건 expression
|
|
164
|
-
*
|
|
165
|
-
* @example
|
|
166
|
-
* ```typescript
|
|
167
|
-
* db.user().where((u) => [expr.lt(u.score, 60)])
|
|
168
|
-
* // WHERE score < 60
|
|
169
|
-
* ```
|
|
170
98
|
*/
|
|
171
99
|
lt(source, target) {
|
|
172
100
|
return new WhereExprUnit({
|
|
@@ -181,12 +109,6 @@ export const expr = {
|
|
|
181
109
|
* @param source - 비교할 column 또는 expression
|
|
182
110
|
* @param target - 비교 대상 값 또는 expression
|
|
183
111
|
* @returns WHERE 조건 expression
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* ```typescript
|
|
187
|
-
* db.user().where((u) => [expr.gte(u.age, 18)])
|
|
188
|
-
* // WHERE age >= 18
|
|
189
|
-
* ```
|
|
190
112
|
*/
|
|
191
113
|
gte(source, target) {
|
|
192
114
|
return new WhereExprUnit({
|
|
@@ -201,12 +123,6 @@ export const expr = {
|
|
|
201
123
|
* @param source - 비교할 column 또는 expression
|
|
202
124
|
* @param target - 비교 대상 값 또는 expression
|
|
203
125
|
* @returns WHERE 조건 expression
|
|
204
|
-
*
|
|
205
|
-
* @example
|
|
206
|
-
* ```typescript
|
|
207
|
-
* db.user().where((u) => [expr.lte(u.score, 100)])
|
|
208
|
-
* // WHERE score <= 100
|
|
209
|
-
* ```
|
|
210
126
|
*/
|
|
211
127
|
lte(source, target) {
|
|
212
128
|
return new WhereExprUnit({
|
|
@@ -224,17 +140,6 @@ export const expr = {
|
|
|
224
140
|
* @param from - 시작 값 (undefined이면 하한 없음)
|
|
225
141
|
* @param to - 끝 값 (undefined이면 상한 없음)
|
|
226
142
|
* @returns WHERE 조건 expression
|
|
227
|
-
*
|
|
228
|
-
* @example
|
|
229
|
-
* ```typescript
|
|
230
|
-
* // Specify range
|
|
231
|
-
* db.user().where((u) => [expr.between(u.age, 18, 65)])
|
|
232
|
-
* // WHERE age BETWEEN 18 AND 65
|
|
233
|
-
*
|
|
234
|
-
* // Specify only lower bound
|
|
235
|
-
* db.user().where((u) => [expr.between(u.age, 18, undefined)])
|
|
236
|
-
* // WHERE age >= 18
|
|
237
|
-
* ```
|
|
238
143
|
*/
|
|
239
144
|
between(source, from, to) {
|
|
240
145
|
return new WhereExprUnit({
|
|
@@ -251,12 +156,6 @@ export const expr = {
|
|
|
251
156
|
*
|
|
252
157
|
* @param source - Column or expression to check
|
|
253
158
|
* @returns WHERE condition expression
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* ```typescript
|
|
257
|
-
* db.user().where((u) => [expr.null(u.deletedAt)])
|
|
258
|
-
* // WHERE deletedAt IS NULL
|
|
259
|
-
* ```
|
|
260
159
|
*/
|
|
261
160
|
null(source) {
|
|
262
161
|
return new WhereExprUnit({
|
|
@@ -275,16 +174,6 @@ export const expr = {
|
|
|
275
174
|
* @param source - Column or expression to search
|
|
276
175
|
* @param pattern - Search pattern (%, _ wildcards available)
|
|
277
176
|
* @returns WHERE condition expression
|
|
278
|
-
*
|
|
279
|
-
* @example
|
|
280
|
-
* ```typescript
|
|
281
|
-
* // Prefix search
|
|
282
|
-
* db.user().where((u) => [expr.like(u.name, "John%")])
|
|
283
|
-
* // WHERE name LIKE 'John%' ESCAPE '\'
|
|
284
|
-
*
|
|
285
|
-
* // Contains search
|
|
286
|
-
* db.user().where((u) => [expr.like(u.email, "%@gmail.com")])
|
|
287
|
-
* ```
|
|
288
177
|
*/
|
|
289
178
|
like(source, pattern) {
|
|
290
179
|
return new WhereExprUnit({
|
|
@@ -301,12 +190,6 @@ export const expr = {
|
|
|
301
190
|
* @param source - Column or expression to search
|
|
302
191
|
* @param pattern - Regular expression pattern
|
|
303
192
|
* @returns WHERE condition expression
|
|
304
|
-
*
|
|
305
|
-
* @example
|
|
306
|
-
* ```typescript
|
|
307
|
-
* db.user().where((u) => [expr.regexp(u.email, "^[a-z]+@")])
|
|
308
|
-
* // MySQL: WHERE email REGEXP '^[a-z]+@'
|
|
309
|
-
* ```
|
|
310
193
|
*/
|
|
311
194
|
regexp(source, pattern) {
|
|
312
195
|
return new WhereExprUnit({
|
|
@@ -323,12 +206,6 @@ export const expr = {
|
|
|
323
206
|
* @param source - Column or expression to compare
|
|
324
207
|
* @param values - List of values to compare against
|
|
325
208
|
* @returns WHERE condition expression
|
|
326
|
-
*
|
|
327
|
-
* @example
|
|
328
|
-
* ```typescript
|
|
329
|
-
* db.user().where((u) => [expr.in(u.status, ["active", "pending"])])
|
|
330
|
-
* // WHERE status IN ('active', 'pending')
|
|
331
|
-
* ```
|
|
332
209
|
*/
|
|
333
210
|
in(source, values) {
|
|
334
211
|
return new WhereExprUnit({
|
|
@@ -346,19 +223,6 @@ export const expr = {
|
|
|
346
223
|
* @param query - Queryable that returns a single column
|
|
347
224
|
* @returns WHERE condition expression
|
|
348
225
|
* @throws {Error} When the subquery does not return a single column
|
|
349
|
-
*
|
|
350
|
-
* @example
|
|
351
|
-
* ```typescript
|
|
352
|
-
* db.user().where((u) => [
|
|
353
|
-
* expr.inQuery(
|
|
354
|
-
* u.id,
|
|
355
|
-
* db.order()
|
|
356
|
-
* .where((o) => [expr.gt(o.amount, 1000)])
|
|
357
|
-
* .select((o) => ({ userId: o.userId }))
|
|
358
|
-
* ),
|
|
359
|
-
* ])
|
|
360
|
-
* // WHERE id IN (SELECT userId FROM Order WHERE amount > 1000)
|
|
361
|
-
* ```
|
|
362
226
|
*/
|
|
363
227
|
inQuery(source, query) {
|
|
364
228
|
const queryDef = query.getSelectQueryDef();
|
|
@@ -378,17 +242,6 @@ export const expr = {
|
|
|
378
242
|
*
|
|
379
243
|
* @param query - Queryable to check for existence
|
|
380
244
|
* @returns WHERE condition expression
|
|
381
|
-
*
|
|
382
|
-
* @example
|
|
383
|
-
* ```typescript
|
|
384
|
-
* // Query users who have orders
|
|
385
|
-
* db.user().where((u) => [
|
|
386
|
-
* expr.exists(
|
|
387
|
-
* db.order().where((o) => [expr.eq(o.userId, u.id)])
|
|
388
|
-
* ),
|
|
389
|
-
* ])
|
|
390
|
-
* // WHERE EXISTS (SELECT 1 FROM Order WHERE userId = User.id)
|
|
391
|
-
* ```
|
|
392
245
|
*/
|
|
393
246
|
exists(query) {
|
|
394
247
|
const { select: _, ...queryDefWithoutSelect } = query.getSelectQueryDef(); // EXISTS는 SELECT 절이 불필요, 패킷 크기 절약
|
|
@@ -404,12 +257,6 @@ export const expr = {
|
|
|
404
257
|
*
|
|
405
258
|
* @param arg - Condition to negate
|
|
406
259
|
* @returns Negated WHERE condition expression
|
|
407
|
-
*
|
|
408
|
-
* @example
|
|
409
|
-
* ```typescript
|
|
410
|
-
* db.user().where((u) => [expr.not(expr.eq(u.status, "deleted"))])
|
|
411
|
-
* // WHERE NOT (status <=> 'deleted')
|
|
412
|
-
* ```
|
|
413
260
|
*/
|
|
414
261
|
not(arg) {
|
|
415
262
|
return new WhereExprUnit({
|
|
@@ -424,17 +271,6 @@ export const expr = {
|
|
|
424
271
|
*
|
|
425
272
|
* @param conditions - List of conditions to combine with AND
|
|
426
273
|
* @returns Combined WHERE condition expression
|
|
427
|
-
*
|
|
428
|
-
* @example
|
|
429
|
-
* ```typescript
|
|
430
|
-
* db.user().where((u) => [
|
|
431
|
-
* expr.and([
|
|
432
|
-
* expr.eq(u.status, "active"),
|
|
433
|
-
* expr.gte(u.age, 18),
|
|
434
|
-
* ]),
|
|
435
|
-
* ])
|
|
436
|
-
* // WHERE (status <=> 'active' AND age >= 18)
|
|
437
|
-
* ```
|
|
438
274
|
*/
|
|
439
275
|
and(conditions) {
|
|
440
276
|
if (conditions.length === 0) {
|
|
@@ -450,17 +286,6 @@ export const expr = {
|
|
|
450
286
|
*
|
|
451
287
|
* @param conditions - List of conditions to combine with OR
|
|
452
288
|
* @returns Combined WHERE condition expression
|
|
453
|
-
*
|
|
454
|
-
* @example
|
|
455
|
-
* ```typescript
|
|
456
|
-
* db.user().where((u) => [
|
|
457
|
-
* expr.or([
|
|
458
|
-
* expr.eq(u.status, "active"),
|
|
459
|
-
* expr.eq(u.status, "pending"),
|
|
460
|
-
* ]),
|
|
461
|
-
* ])
|
|
462
|
-
* // WHERE (status <=> 'active' OR status <=> 'pending')
|
|
463
|
-
* ```
|
|
464
289
|
*/
|
|
465
290
|
or(conditions) {
|
|
466
291
|
if (conditions.length === 0) {
|
|
@@ -480,14 +305,6 @@ export const expr = {
|
|
|
480
305
|
*
|
|
481
306
|
* @param args - Strings to concatenate
|
|
482
307
|
* @returns Concatenated string expression
|
|
483
|
-
*
|
|
484
|
-
* @example
|
|
485
|
-
* ```typescript
|
|
486
|
-
* db.user().select((u) => ({
|
|
487
|
-
* fullName: expr.concat(u.firstName, " ", u.lastName),
|
|
488
|
-
* }))
|
|
489
|
-
* // SELECT CONCAT(firstName, ' ', lastName) AS fullName
|
|
490
|
-
* ```
|
|
491
308
|
*/
|
|
492
309
|
concat(...args) {
|
|
493
310
|
return new ExprUnit("string", {
|
|
@@ -501,14 +318,6 @@ export const expr = {
|
|
|
501
318
|
* @param source - Original string
|
|
502
319
|
* @param length - Number of characters to extract
|
|
503
320
|
* @returns Extracted string expression
|
|
504
|
-
*
|
|
505
|
-
* @example
|
|
506
|
-
* ```typescript
|
|
507
|
-
* db.user().select((u) => ({
|
|
508
|
-
* initial: expr.left(u.name, 1),
|
|
509
|
-
* }))
|
|
510
|
-
* // SELECT LEFT(name, 1) AS initial
|
|
511
|
-
* ```
|
|
512
321
|
*/
|
|
513
322
|
left(source, length) {
|
|
514
323
|
return new ExprUnit("string", {
|
|
@@ -523,14 +332,6 @@ export const expr = {
|
|
|
523
332
|
* @param source - Original string
|
|
524
333
|
* @param length - Number of characters to extract
|
|
525
334
|
* @returns Extracted string expression
|
|
526
|
-
*
|
|
527
|
-
* @example
|
|
528
|
-
* ```typescript
|
|
529
|
-
* db.phone().select((p) => ({
|
|
530
|
-
* lastFour: expr.right(p.number, 4),
|
|
531
|
-
* }))
|
|
532
|
-
* // SELECT RIGHT(number, 4) AS lastFour
|
|
533
|
-
* ```
|
|
534
335
|
*/
|
|
535
336
|
right(source, length) {
|
|
536
337
|
return new ExprUnit("string", {
|
|
@@ -544,14 +345,6 @@ export const expr = {
|
|
|
544
345
|
*
|
|
545
346
|
* @param source - Original string
|
|
546
347
|
* @returns String expression with whitespace removed
|
|
547
|
-
*
|
|
548
|
-
* @example
|
|
549
|
-
* ```typescript
|
|
550
|
-
* db.user().select((u) => ({
|
|
551
|
-
* name: expr.trim(u.name),
|
|
552
|
-
* }))
|
|
553
|
-
* // SELECT TRIM(name) AS name
|
|
554
|
-
* ```
|
|
555
348
|
*/
|
|
556
349
|
trim(source) {
|
|
557
350
|
return new ExprUnit("string", {
|
|
@@ -568,15 +361,6 @@ export const expr = {
|
|
|
568
361
|
* @param length - Target length
|
|
569
362
|
* @param fillString - String to use for padding
|
|
570
363
|
* @returns Padded string expression
|
|
571
|
-
*
|
|
572
|
-
* @example
|
|
573
|
-
* ```typescript
|
|
574
|
-
* db.order().select((o) => ({
|
|
575
|
-
* orderNo: expr.padStart(expr.cast(o.id, { type: "varchar", length: 10 }), 8, "0"),
|
|
576
|
-
* }))
|
|
577
|
-
* // SELECT LPAD(CAST(id AS VARCHAR(10)), 8, '0') AS orderNo
|
|
578
|
-
* // Result: "00000123"
|
|
579
|
-
* ```
|
|
580
364
|
*/
|
|
581
365
|
padStart(source, length, fillString) {
|
|
582
366
|
return new ExprUnit("string", {
|
|
@@ -593,14 +377,6 @@ export const expr = {
|
|
|
593
377
|
* @param from - String to find
|
|
594
378
|
* @param to - Replacement string
|
|
595
379
|
* @returns Replaced string expression
|
|
596
|
-
*
|
|
597
|
-
* @example
|
|
598
|
-
* ```typescript
|
|
599
|
-
* db.user().select((u) => ({
|
|
600
|
-
* phone: expr.replace(u.phone, "-", ""),
|
|
601
|
-
* }))
|
|
602
|
-
* // SELECT REPLACE(phone, '-', '') AS phone
|
|
603
|
-
* ```
|
|
604
380
|
*/
|
|
605
381
|
replace(source, from, to) {
|
|
606
382
|
return new ExprUnit("string", {
|
|
@@ -615,14 +391,6 @@ export const expr = {
|
|
|
615
391
|
*
|
|
616
392
|
* @param source - Original string
|
|
617
393
|
* @returns Uppercase string expression
|
|
618
|
-
*
|
|
619
|
-
* @example
|
|
620
|
-
* ```typescript
|
|
621
|
-
* db.user().select((u) => ({
|
|
622
|
-
* code: expr.upper(u.code),
|
|
623
|
-
* }))
|
|
624
|
-
* // SELECT UPPER(code) AS code
|
|
625
|
-
* ```
|
|
626
394
|
*/
|
|
627
395
|
upper(source) {
|
|
628
396
|
return new ExprUnit("string", {
|
|
@@ -635,14 +403,6 @@ export const expr = {
|
|
|
635
403
|
*
|
|
636
404
|
* @param source - Original string
|
|
637
405
|
* @returns Lowercase string expression
|
|
638
|
-
*
|
|
639
|
-
* @example
|
|
640
|
-
* ```typescript
|
|
641
|
-
* db.user().select((u) => ({
|
|
642
|
-
* email: expr.lower(u.email),
|
|
643
|
-
* }))
|
|
644
|
-
* // SELECT LOWER(email) AS email
|
|
645
|
-
* ```
|
|
646
406
|
*/
|
|
647
407
|
lower(source) {
|
|
648
408
|
return new ExprUnit("string", {
|
|
@@ -655,14 +415,6 @@ export const expr = {
|
|
|
655
415
|
*
|
|
656
416
|
* @param source - Original string
|
|
657
417
|
* @returns Character count
|
|
658
|
-
*
|
|
659
|
-
* @example
|
|
660
|
-
* ```typescript
|
|
661
|
-
* db.user().select((u) => ({
|
|
662
|
-
* nameLength: expr.length(u.name),
|
|
663
|
-
* }))
|
|
664
|
-
* // SELECT CHAR_LENGTH(name) AS nameLength
|
|
665
|
-
* ```
|
|
666
418
|
*/
|
|
667
419
|
length(source) {
|
|
668
420
|
return new ExprUnit("number", {
|
|
@@ -677,14 +429,6 @@ export const expr = {
|
|
|
677
429
|
*
|
|
678
430
|
* @param source - Original string
|
|
679
431
|
* @returns Byte count
|
|
680
|
-
*
|
|
681
|
-
* @example
|
|
682
|
-
* ```typescript
|
|
683
|
-
* db.user().select((u) => ({
|
|
684
|
-
* byteLen: expr.byteLength(u.name),
|
|
685
|
-
* }))
|
|
686
|
-
* // SELECT OCTET_LENGTH(name) AS byteLen
|
|
687
|
-
* ```
|
|
688
432
|
*/
|
|
689
433
|
byteLength(source) {
|
|
690
434
|
return new ExprUnit("number", {
|
|
@@ -701,15 +445,6 @@ export const expr = {
|
|
|
701
445
|
* @param start - Start position (starting from 1)
|
|
702
446
|
* @param length - Length to extract (to the end if omitted)
|
|
703
447
|
* @returns Extracted string expression
|
|
704
|
-
*
|
|
705
|
-
* @example
|
|
706
|
-
* ```typescript
|
|
707
|
-
* db.user().select((u) => ({
|
|
708
|
-
* // From "Hello World", 5 characters starting at index 1: "Hello"
|
|
709
|
-
* prefix: expr.substring(u.name, 1, 5),
|
|
710
|
-
* }))
|
|
711
|
-
* // SELECT SUBSTRING(name, 1, 5) AS prefix
|
|
712
|
-
* ```
|
|
713
448
|
*/
|
|
714
449
|
substring(source, start, length) {
|
|
715
450
|
return new ExprUnit("string", {
|
|
@@ -727,15 +462,6 @@ export const expr = {
|
|
|
727
462
|
* @param source - String to search in
|
|
728
463
|
* @param search - String to find
|
|
729
464
|
* @returns Position (starting from 1, 0 if not found)
|
|
730
|
-
*
|
|
731
|
-
* @example
|
|
732
|
-
* ```typescript
|
|
733
|
-
* db.user().select((u) => ({
|
|
734
|
-
* atPos: expr.indexOf(u.email, "@"),
|
|
735
|
-
* }))
|
|
736
|
-
* // SELECT LOCATE('@', email) AS atPos (MySQL)
|
|
737
|
-
* // "john@example.com" → 5
|
|
738
|
-
* ```
|
|
739
465
|
*/
|
|
740
466
|
indexOf(source, search) {
|
|
741
467
|
return new ExprUnit("number", {
|
|
@@ -751,14 +477,6 @@ export const expr = {
|
|
|
751
477
|
*
|
|
752
478
|
* @param source - Original number
|
|
753
479
|
* @returns Absolute value expression
|
|
754
|
-
*
|
|
755
|
-
* @example
|
|
756
|
-
* ```typescript
|
|
757
|
-
* db.account().select((a) => ({
|
|
758
|
-
* balance: expr.abs(a.balance),
|
|
759
|
-
* }))
|
|
760
|
-
* // SELECT ABS(balance) AS balance
|
|
761
|
-
* ```
|
|
762
480
|
*/
|
|
763
481
|
abs(source) {
|
|
764
482
|
return new ExprUnit("number", {
|
|
@@ -772,15 +490,6 @@ export const expr = {
|
|
|
772
490
|
* @param source - Original number
|
|
773
491
|
* @param digits - Number of decimal places
|
|
774
492
|
* @returns Rounded number expression
|
|
775
|
-
*
|
|
776
|
-
* @example
|
|
777
|
-
* ```typescript
|
|
778
|
-
* db.product().select((p) => ({
|
|
779
|
-
* price: expr.round(p.price, 2),
|
|
780
|
-
* }))
|
|
781
|
-
* // SELECT ROUND(price, 2) AS price
|
|
782
|
-
* // 123.456 → 123.46
|
|
783
|
-
* ```
|
|
784
493
|
*/
|
|
785
494
|
round(source, digits) {
|
|
786
495
|
return new ExprUnit("number", {
|
|
@@ -794,15 +503,6 @@ export const expr = {
|
|
|
794
503
|
*
|
|
795
504
|
* @param source - Original number
|
|
796
505
|
* @returns Ceiling number expression
|
|
797
|
-
*
|
|
798
|
-
* @example
|
|
799
|
-
* ```typescript
|
|
800
|
-
* db.order().select((o) => ({
|
|
801
|
-
* pages: expr.ceil(expr.multiply(o.itemCount, 0.1)),
|
|
802
|
-
* }))
|
|
803
|
-
* // SELECT CEILING(itemCount / 10) AS pages
|
|
804
|
-
* // 25 / 10 = 2.5 → 3
|
|
805
|
-
* ```
|
|
806
506
|
*/
|
|
807
507
|
ceil(source) {
|
|
808
508
|
return new ExprUnit("number", {
|
|
@@ -815,15 +515,6 @@ export const expr = {
|
|
|
815
515
|
*
|
|
816
516
|
* @param source - Original number
|
|
817
517
|
* @returns Floor number expression
|
|
818
|
-
*
|
|
819
|
-
* @example
|
|
820
|
-
* ```typescript
|
|
821
|
-
* db.user().select((u) => ({
|
|
822
|
-
* ageGroup: expr.floor(expr.multiply(u.age, 0.1)),
|
|
823
|
-
* }))
|
|
824
|
-
* // SELECT FLOOR(age / 10) AS ageGroup
|
|
825
|
-
* // 25 / 10 = 2.5 → 2
|
|
826
|
-
* ```
|
|
827
518
|
*/
|
|
828
519
|
floor(source) {
|
|
829
520
|
return new ExprUnit("number", {
|
|
@@ -838,14 +529,6 @@ export const expr = {
|
|
|
838
529
|
*
|
|
839
530
|
* @param source - DateTime or DateOnly expression
|
|
840
531
|
* @returns Year (4-digit number)
|
|
841
|
-
*
|
|
842
|
-
* @example
|
|
843
|
-
* ```typescript
|
|
844
|
-
* db.user().select((u) => ({
|
|
845
|
-
* birthYear: expr.year(u.birthDate),
|
|
846
|
-
* }))
|
|
847
|
-
* // SELECT YEAR(birthDate) AS birthYear
|
|
848
|
-
* ```
|
|
849
532
|
*/
|
|
850
533
|
year(source) {
|
|
851
534
|
return new ExprUnit("number", {
|
|
@@ -858,14 +541,6 @@ export const expr = {
|
|
|
858
541
|
*
|
|
859
542
|
* @param source - DateTime or DateOnly expression
|
|
860
543
|
* @returns Month (1~12)
|
|
861
|
-
*
|
|
862
|
-
* @example
|
|
863
|
-
* ```typescript
|
|
864
|
-
* db.order().select((o) => ({
|
|
865
|
-
* orderMonth: expr.month(o.createdAt),
|
|
866
|
-
* }))
|
|
867
|
-
* // SELECT MONTH(createdAt) AS orderMonth
|
|
868
|
-
* ```
|
|
869
544
|
*/
|
|
870
545
|
month(source) {
|
|
871
546
|
return new ExprUnit("number", {
|
|
@@ -878,14 +553,6 @@ export const expr = {
|
|
|
878
553
|
*
|
|
879
554
|
* @param source - DateTime or DateOnly expression
|
|
880
555
|
* @returns Day (1~31)
|
|
881
|
-
*
|
|
882
|
-
* @example
|
|
883
|
-
* ```typescript
|
|
884
|
-
* db.user().select((u) => ({
|
|
885
|
-
* birthDay: expr.day(u.birthDate),
|
|
886
|
-
* }))
|
|
887
|
-
* // SELECT DAY(birthDate) AS birthDay
|
|
888
|
-
* ```
|
|
889
556
|
*/
|
|
890
557
|
day(source) {
|
|
891
558
|
return new ExprUnit("number", {
|
|
@@ -898,14 +565,6 @@ export const expr = {
|
|
|
898
565
|
*
|
|
899
566
|
* @param source - DateTime or Time expression
|
|
900
567
|
* @returns Hour (0~23)
|
|
901
|
-
*
|
|
902
|
-
* @example
|
|
903
|
-
* ```typescript
|
|
904
|
-
* db.log().select((l) => ({
|
|
905
|
-
* logHour: expr.hour(l.createdAt),
|
|
906
|
-
* }))
|
|
907
|
-
* // SELECT HOUR(createdAt) AS logHour
|
|
908
|
-
* ```
|
|
909
568
|
*/
|
|
910
569
|
hour(source) {
|
|
911
570
|
return new ExprUnit("number", {
|
|
@@ -918,14 +577,6 @@ export const expr = {
|
|
|
918
577
|
*
|
|
919
578
|
* @param source - DateTime or Time expression
|
|
920
579
|
* @returns Minute (0~59)
|
|
921
|
-
*
|
|
922
|
-
* @example
|
|
923
|
-
* ```typescript
|
|
924
|
-
* db.log().select((l) => ({
|
|
925
|
-
* logMinute: expr.minute(l.createdAt),
|
|
926
|
-
* }))
|
|
927
|
-
* // SELECT MINUTE(createdAt) AS logMinute
|
|
928
|
-
* ```
|
|
929
580
|
*/
|
|
930
581
|
minute(source) {
|
|
931
582
|
return new ExprUnit("number", {
|
|
@@ -938,14 +589,6 @@ export const expr = {
|
|
|
938
589
|
*
|
|
939
590
|
* @param source - DateTime or Time expression
|
|
940
591
|
* @returns Second (0~59)
|
|
941
|
-
*
|
|
942
|
-
* @example
|
|
943
|
-
* ```typescript
|
|
944
|
-
* db.log().select((l) => ({
|
|
945
|
-
* logSecond: expr.second(l.createdAt),
|
|
946
|
-
* }))
|
|
947
|
-
* // SELECT SECOND(createdAt) AS logSecond
|
|
948
|
-
* ```
|
|
949
592
|
*/
|
|
950
593
|
second(source) {
|
|
951
594
|
return new ExprUnit("number", {
|
|
@@ -960,14 +603,6 @@ export const expr = {
|
|
|
960
603
|
*
|
|
961
604
|
* @param source - DateOnly expression
|
|
962
605
|
* @returns ISO week number
|
|
963
|
-
*
|
|
964
|
-
* @example
|
|
965
|
-
* ```typescript
|
|
966
|
-
* db.order().select((o) => ({
|
|
967
|
-
* weekNum: expr.isoWeek(o.orderDate),
|
|
968
|
-
* }))
|
|
969
|
-
* // SELECT WEEK(orderDate, 3) AS weekNum (MySQL)
|
|
970
|
-
* ```
|
|
971
606
|
*/
|
|
972
607
|
isoWeek(source) {
|
|
973
608
|
return new ExprUnit("number", {
|
|
@@ -982,14 +617,6 @@ export const expr = {
|
|
|
982
617
|
*
|
|
983
618
|
* @param source - DateOnly expression
|
|
984
619
|
* @returns Week start date (Monday)
|
|
985
|
-
*
|
|
986
|
-
* @example
|
|
987
|
-
* ```typescript
|
|
988
|
-
* db.order().select((o) => ({
|
|
989
|
-
* weekStart: expr.isoWeekStartDate(o.orderDate),
|
|
990
|
-
* }))
|
|
991
|
-
* // 2024-01-10 (Wed) → 2024-01-08 (Mon)
|
|
992
|
-
* ```
|
|
993
620
|
*/
|
|
994
621
|
isoWeekStartDate(source) {
|
|
995
622
|
return new ExprUnit("DateOnly", {
|
|
@@ -1004,14 +631,6 @@ export const expr = {
|
|
|
1004
631
|
*
|
|
1005
632
|
* @param source - DateOnly expression
|
|
1006
633
|
* @returns Year-month string (YYYYMM)
|
|
1007
|
-
*
|
|
1008
|
-
* @example
|
|
1009
|
-
* ```typescript
|
|
1010
|
-
* db.order().select((o) => ({
|
|
1011
|
-
* yearMonth: expr.isoYearMonth(o.orderDate),
|
|
1012
|
-
* }))
|
|
1013
|
-
* // 2024-01-15 → "202401"
|
|
1014
|
-
* ```
|
|
1015
634
|
*/
|
|
1016
635
|
isoYearMonth(source) {
|
|
1017
636
|
return new ExprUnit("string", {
|
|
@@ -1026,14 +645,6 @@ export const expr = {
|
|
|
1026
645
|
* @param from - Start date
|
|
1027
646
|
* @param to - End date
|
|
1028
647
|
* @returns Difference value (to - from)
|
|
1029
|
-
*
|
|
1030
|
-
* @example
|
|
1031
|
-
* ```typescript
|
|
1032
|
-
* db.user().select((u) => ({
|
|
1033
|
-
* age: expr.dateDiff("year", u.birthDate, expr.val("DateOnly", DateOnly.today())),
|
|
1034
|
-
* }))
|
|
1035
|
-
* // SELECT DATEDIFF(year, birthDate, '2024-01-15') AS age
|
|
1036
|
-
* ```
|
|
1037
648
|
*/
|
|
1038
649
|
dateDiff(unit, from, to) {
|
|
1039
650
|
return new ExprUnit("number", {
|
|
@@ -1050,14 +661,6 @@ export const expr = {
|
|
|
1050
661
|
* @param source - Original date
|
|
1051
662
|
* @param value - Value to add (negative allowed)
|
|
1052
663
|
* @returns Calculated date
|
|
1053
|
-
*
|
|
1054
|
-
* @example
|
|
1055
|
-
* ```typescript
|
|
1056
|
-
* db.subscription().select((s) => ({
|
|
1057
|
-
* expiresAt: expr.dateAdd("month", s.startDate, 12),
|
|
1058
|
-
* }))
|
|
1059
|
-
* // SELECT DATEADD(month, 12, startDate) AS expiresAt
|
|
1060
|
-
* ```
|
|
1061
664
|
*/
|
|
1062
665
|
dateAdd(unit, source, value) {
|
|
1063
666
|
return new ExprUnit(source.dataType, {
|
|
@@ -1075,15 +678,6 @@ export const expr = {
|
|
|
1075
678
|
* @param source - Date expression
|
|
1076
679
|
* @param format - Format string (e.g., "%Y-%m-%d")
|
|
1077
680
|
* @returns Formatted string expression
|
|
1078
|
-
*
|
|
1079
|
-
* @example
|
|
1080
|
-
* ```typescript
|
|
1081
|
-
* db.order().select((o) => ({
|
|
1082
|
-
* orderDate: expr.formatDate(o.createdAt, "%Y-%m-%d"),
|
|
1083
|
-
* }))
|
|
1084
|
-
* // SELECT DATE_FORMAT(createdAt, '%Y-%m-%d') AS orderDate (MySQL)
|
|
1085
|
-
* // 2024-01-15 10:30:00 → "2024-01-15"
|
|
1086
|
-
* ```
|
|
1087
681
|
*/
|
|
1088
682
|
formatDate(source, format) {
|
|
1089
683
|
return new ExprUnit("string", {
|
|
@@ -1101,14 +695,6 @@ export const expr = {
|
|
|
1101
695
|
*
|
|
1102
696
|
* @param args - Values to inspect (last is default value)
|
|
1103
697
|
* @returns First non-null value
|
|
1104
|
-
*
|
|
1105
|
-
* @example
|
|
1106
|
-
* ```typescript
|
|
1107
|
-
* db.user().select((u) => ({
|
|
1108
|
-
* displayName: expr.coalesce(u.nickname, u.name, "Guest"),
|
|
1109
|
-
* }))
|
|
1110
|
-
* // SELECT COALESCE(nickname, name, 'Guest') AS displayName
|
|
1111
|
-
* ```
|
|
1112
698
|
*/
|
|
1113
699
|
coalesce,
|
|
1114
700
|
/**
|
|
@@ -1119,15 +705,6 @@ export const expr = {
|
|
|
1119
705
|
* @param source - Original value
|
|
1120
706
|
* @param value - Value to compare
|
|
1121
707
|
* @returns NULL or original value
|
|
1122
|
-
*
|
|
1123
|
-
* @example
|
|
1124
|
-
* ```typescript
|
|
1125
|
-
* db.user().select((u) => ({
|
|
1126
|
-
* // Convert empty string to NULL
|
|
1127
|
-
* bio: expr.nullIf(u.bio, ""),
|
|
1128
|
-
* }))
|
|
1129
|
-
* // SELECT NULLIF(bio, '') AS bio
|
|
1130
|
-
* ```
|
|
1131
708
|
*/
|
|
1132
709
|
nullIf(source, value) {
|
|
1133
710
|
return new ExprUnit(source.dataType, {
|
|
@@ -1143,14 +720,6 @@ export const expr = {
|
|
|
1143
720
|
*
|
|
1144
721
|
* @param condition - Condition to transform
|
|
1145
722
|
* @returns boolean expression
|
|
1146
|
-
*
|
|
1147
|
-
* @example
|
|
1148
|
-
* ```typescript
|
|
1149
|
-
* db.user().select((u) => ({
|
|
1150
|
-
* isActive: expr.is(expr.eq(u.status, "active")),
|
|
1151
|
-
* }))
|
|
1152
|
-
* // SELECT (status <=> 'active') AS isActive
|
|
1153
|
-
* ```
|
|
1154
723
|
*/
|
|
1155
724
|
is(condition) {
|
|
1156
725
|
return new ExprUnit("boolean", {
|
|
@@ -1164,18 +733,6 @@ export const expr = {
|
|
|
1164
733
|
* 메서드 체이닝으로 조건 분기 구성
|
|
1165
734
|
*
|
|
1166
735
|
* @returns SwitchExprBuilder instance
|
|
1167
|
-
*
|
|
1168
|
-
* @example
|
|
1169
|
-
* ```typescript
|
|
1170
|
-
* db.user().select((u) => ({
|
|
1171
|
-
* grade: expr.switch<string>()
|
|
1172
|
-
* .case(expr.gte(u.score, 90), "A")
|
|
1173
|
-
* .case(expr.gte(u.score, 80), "B")
|
|
1174
|
-
* .case(expr.gte(u.score, 70), "C")
|
|
1175
|
-
* .default("F"),
|
|
1176
|
-
* }))
|
|
1177
|
-
* // SELECT CASE WHEN score >= 90 THEN 'A' ... ELSE 'F' END AS grade
|
|
1178
|
-
* ```
|
|
1179
736
|
*/
|
|
1180
737
|
switch() {
|
|
1181
738
|
return createSwitchBuilder();
|
|
@@ -1187,14 +744,6 @@ export const expr = {
|
|
|
1187
744
|
* @param then - Value when condition is true
|
|
1188
745
|
* @param else_ - Value when condition is false
|
|
1189
746
|
* @returns Conditional value expression
|
|
1190
|
-
*
|
|
1191
|
-
* @example
|
|
1192
|
-
* ```typescript
|
|
1193
|
-
* db.user().select((u) => ({
|
|
1194
|
-
* type: expr.if(expr.gte(u.age, 18), "adult", "minor"),
|
|
1195
|
-
* }))
|
|
1196
|
-
* // SELECT IF(age >= 18, 'adult', 'minor') AS type
|
|
1197
|
-
* ```
|
|
1198
747
|
*/
|
|
1199
748
|
if(condition, then, else_) {
|
|
1200
749
|
const allValues = [then, else_];
|
|
@@ -1229,17 +778,6 @@ export const expr = {
|
|
|
1229
778
|
* @param arg - Column to count (all rows if omitted)
|
|
1230
779
|
* @param distinct - If true, remove duplicates
|
|
1231
780
|
* @returns Row count
|
|
1232
|
-
*
|
|
1233
|
-
* @example
|
|
1234
|
-
* ```typescript
|
|
1235
|
-
* // Total row count
|
|
1236
|
-
* db.user().select(() => ({ total: expr.count() }))
|
|
1237
|
-
*
|
|
1238
|
-
* // Distinct count
|
|
1239
|
-
* db.order().select((o) => ({
|
|
1240
|
-
* uniqueCustomers: expr.count(o.customerId, true),
|
|
1241
|
-
* }))
|
|
1242
|
-
* ```
|
|
1243
781
|
*/
|
|
1244
782
|
count(arg, distinct) {
|
|
1245
783
|
return new ExprUnit("number", {
|
|
@@ -1255,14 +793,6 @@ export const expr = {
|
|
|
1255
793
|
*
|
|
1256
794
|
* @param arg - Number column to sum
|
|
1257
795
|
* @returns Sum (or NULL)
|
|
1258
|
-
*
|
|
1259
|
-
* @example
|
|
1260
|
-
* ```typescript
|
|
1261
|
-
* db.order().groupBy((o) => o.userId).select((o) => ({
|
|
1262
|
-
* userId: o.userId,
|
|
1263
|
-
* totalAmount: expr.sum(o.amount),
|
|
1264
|
-
* }))
|
|
1265
|
-
* ```
|
|
1266
796
|
*/
|
|
1267
797
|
sum(arg) {
|
|
1268
798
|
return new ExprUnit("number", {
|
|
@@ -1277,14 +807,6 @@ export const expr = {
|
|
|
1277
807
|
*
|
|
1278
808
|
* @param arg - Number column to average
|
|
1279
809
|
* @returns Average (or NULL)
|
|
1280
|
-
*
|
|
1281
|
-
* @example
|
|
1282
|
-
* ```typescript
|
|
1283
|
-
* db.product().groupBy((p) => p.categoryId).select((p) => ({
|
|
1284
|
-
* categoryId: p.categoryId,
|
|
1285
|
-
* avgPrice: expr.avg(p.price),
|
|
1286
|
-
* }))
|
|
1287
|
-
* ```
|
|
1288
810
|
*/
|
|
1289
811
|
avg(arg) {
|
|
1290
812
|
return new ExprUnit("number", {
|
|
@@ -1299,14 +821,6 @@ export const expr = {
|
|
|
1299
821
|
*
|
|
1300
822
|
* @param arg - Column to find maximum of
|
|
1301
823
|
* @returns Maximum value (or NULL)
|
|
1302
|
-
*
|
|
1303
|
-
* @example
|
|
1304
|
-
* ```typescript
|
|
1305
|
-
* db.order().groupBy((o) => o.userId).select((o) => ({
|
|
1306
|
-
* userId: o.userId,
|
|
1307
|
-
* lastOrderDate: expr.max(o.createdAt),
|
|
1308
|
-
* }))
|
|
1309
|
-
* ```
|
|
1310
824
|
*/
|
|
1311
825
|
max(arg) {
|
|
1312
826
|
return new ExprUnit(arg.dataType, {
|
|
@@ -1321,14 +835,6 @@ export const expr = {
|
|
|
1321
835
|
*
|
|
1322
836
|
* @param arg - Column to find minimum of
|
|
1323
837
|
* @returns Minimum value (or NULL)
|
|
1324
|
-
*
|
|
1325
|
-
* @example
|
|
1326
|
-
* ```typescript
|
|
1327
|
-
* db.product().groupBy((p) => p.categoryId).select((p) => ({
|
|
1328
|
-
* categoryId: p.categoryId,
|
|
1329
|
-
* minPrice: expr.min(p.price),
|
|
1330
|
-
* }))
|
|
1331
|
-
* ```
|
|
1332
838
|
*/
|
|
1333
839
|
min(arg) {
|
|
1334
840
|
return new ExprUnit(arg.dataType, {
|
|
@@ -1343,14 +849,6 @@ export const expr = {
|
|
|
1343
849
|
*
|
|
1344
850
|
* @param args - Values to compare
|
|
1345
851
|
* @returns Greatest value
|
|
1346
|
-
*
|
|
1347
|
-
* @example
|
|
1348
|
-
* ```typescript
|
|
1349
|
-
* db.product().select((p) => ({
|
|
1350
|
-
* effectivePrice: expr.greatest(p.price, p.minPrice),
|
|
1351
|
-
* }))
|
|
1352
|
-
* // SELECT GREATEST(price, minPrice) AS effectivePrice
|
|
1353
|
-
* ```
|
|
1354
852
|
*/
|
|
1355
853
|
greatest(...args) {
|
|
1356
854
|
return new ExprUnit(findDataType(args), {
|
|
@@ -1363,14 +861,6 @@ export const expr = {
|
|
|
1363
861
|
*
|
|
1364
862
|
* @param args - Values to compare
|
|
1365
863
|
* @returns Least value
|
|
1366
|
-
*
|
|
1367
|
-
* @example
|
|
1368
|
-
* ```typescript
|
|
1369
|
-
* db.product().select((p) => ({
|
|
1370
|
-
* effectivePrice: expr.least(p.price, p.maxDiscount),
|
|
1371
|
-
* }))
|
|
1372
|
-
* // SELECT LEAST(price, maxDiscount) AS effectivePrice
|
|
1373
|
-
* ```
|
|
1374
864
|
*/
|
|
1375
865
|
least(...args) {
|
|
1376
866
|
return new ExprUnit(findDataType(args), {
|
|
@@ -1382,14 +872,6 @@ export const expr = {
|
|
|
1382
872
|
* 행 번호 (ROW_NUMBER 없이 모든 행에 순번 부여)
|
|
1383
873
|
*
|
|
1384
874
|
* @returns Row number (starting from 1)
|
|
1385
|
-
*
|
|
1386
|
-
* @example
|
|
1387
|
-
* ```typescript
|
|
1388
|
-
* db.user().select((u) => ({
|
|
1389
|
-
* rowNum: expr.rowNum(),
|
|
1390
|
-
* name: u.name,
|
|
1391
|
-
* }))
|
|
1392
|
-
* ```
|
|
1393
875
|
*/
|
|
1394
876
|
rowNum() {
|
|
1395
877
|
return new ExprUnit("number", {
|
|
@@ -1402,12 +884,6 @@ export const expr = {
|
|
|
1402
884
|
* 0과 1 사이의 난수 반환. 주로 ORDER BY에서 무작위 정렬에 사용
|
|
1403
885
|
*
|
|
1404
886
|
* @returns Random number between 0 and 1
|
|
1405
|
-
*
|
|
1406
|
-
* @example
|
|
1407
|
-
* ```typescript
|
|
1408
|
-
* // Random sorting
|
|
1409
|
-
* db.user().orderBy(() => expr.random()).limit(10)
|
|
1410
|
-
* ```
|
|
1411
887
|
*/
|
|
1412
888
|
random() {
|
|
1413
889
|
return new ExprUnit("number", {
|
|
@@ -1420,14 +896,6 @@ export const expr = {
|
|
|
1420
896
|
* @param source - Expression to transform
|
|
1421
897
|
* @param targetType - Target data type
|
|
1422
898
|
* @returns Transformed expression
|
|
1423
|
-
*
|
|
1424
|
-
* @example
|
|
1425
|
-
* ```typescript
|
|
1426
|
-
* db.order().select((o) => ({
|
|
1427
|
-
* idStr: expr.cast(o.id, { type: "varchar", length: 20 }),
|
|
1428
|
-
* }))
|
|
1429
|
-
* // SELECT CAST(id AS VARCHAR(20)) AS idStr
|
|
1430
|
-
* ```
|
|
1431
899
|
*/
|
|
1432
900
|
cast(source, targetType) {
|
|
1433
901
|
return new ExprUnit(dataTypeStrToColumnPrimitiveStr[targetType.type], {
|
|
@@ -1444,20 +912,6 @@ export const expr = {
|
|
|
1444
912
|
* @param dataType - Data type of the returned value
|
|
1445
913
|
* @param queryable - Queryable that returns a scalar value
|
|
1446
914
|
* @returns Subquery result expression
|
|
1447
|
-
*
|
|
1448
|
-
* @example
|
|
1449
|
-
* ```typescript
|
|
1450
|
-
* db.user().select((u) => ({
|
|
1451
|
-
* id: u.id,
|
|
1452
|
-
* postCount: expr.subquery(
|
|
1453
|
-
* "number",
|
|
1454
|
-
* db.post()
|
|
1455
|
-
* .where((p) => [expr.eq(p.userId, u.id)])
|
|
1456
|
-
* .select(() => ({ cnt: expr.count() }))
|
|
1457
|
-
* ),
|
|
1458
|
-
* }))
|
|
1459
|
-
* // SELECT id, (SELECT COUNT(*) FROM Post WHERE userId = User.id) AS postCount
|
|
1460
|
-
* ```
|
|
1461
915
|
*/
|
|
1462
916
|
subquery(dataType, queryable) {
|
|
1463
917
|
return new ExprUnit(dataType, {
|
|
@@ -1474,18 +928,6 @@ export const expr = {
|
|
|
1474
928
|
*
|
|
1475
929
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1476
930
|
* @returns Row number (starting from 1)
|
|
1477
|
-
*
|
|
1478
|
-
* @example
|
|
1479
|
-
* ```typescript
|
|
1480
|
-
* db.order().select((o) => ({
|
|
1481
|
-
* ...o,
|
|
1482
|
-
* rowNum: expr.rowNumber({
|
|
1483
|
-
* partitionBy: [o.userId],
|
|
1484
|
-
* orderBy: [[o.createdAt, "DESC"]],
|
|
1485
|
-
* }),
|
|
1486
|
-
* }))
|
|
1487
|
-
* // SELECT *, ROW_NUMBER() OVER (PARTITION BY userId ORDER BY createdAt DESC)
|
|
1488
|
-
* ```
|
|
1489
931
|
*/
|
|
1490
932
|
rowNumber(spec) {
|
|
1491
933
|
return new ExprUnit("number", {
|
|
@@ -1499,16 +941,6 @@ export const expr = {
|
|
|
1499
941
|
*
|
|
1500
942
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1501
943
|
* @returns Rank (skips after ties: 1, 1, 3)
|
|
1502
|
-
*
|
|
1503
|
-
* @example
|
|
1504
|
-
* ```typescript
|
|
1505
|
-
* db.student().select((s) => ({
|
|
1506
|
-
* name: s.name,
|
|
1507
|
-
* rank: expr.rank({
|
|
1508
|
-
* orderBy: [[s.score, "DESC"]],
|
|
1509
|
-
* }),
|
|
1510
|
-
* }))
|
|
1511
|
-
* ```
|
|
1512
944
|
*/
|
|
1513
945
|
rank(spec) {
|
|
1514
946
|
return new ExprUnit("number", {
|
|
@@ -1522,16 +954,6 @@ export const expr = {
|
|
|
1522
954
|
*
|
|
1523
955
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1524
956
|
* @returns Dense rank (consecutive after ties: 1, 1, 2)
|
|
1525
|
-
*
|
|
1526
|
-
* @example
|
|
1527
|
-
* ```typescript
|
|
1528
|
-
* db.student().select((s) => ({
|
|
1529
|
-
* name: s.name,
|
|
1530
|
-
* denseRank: expr.denseRank({
|
|
1531
|
-
* orderBy: [[s.score, "DESC"]],
|
|
1532
|
-
* }),
|
|
1533
|
-
* }))
|
|
1534
|
-
* ```
|
|
1535
957
|
*/
|
|
1536
958
|
denseRank(spec) {
|
|
1537
959
|
return new ExprUnit("number", {
|
|
@@ -1546,17 +968,6 @@ export const expr = {
|
|
|
1546
968
|
* @param n - Number of groups to split into
|
|
1547
969
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1548
970
|
* @returns Group number (1 ~ n)
|
|
1549
|
-
*
|
|
1550
|
-
* @example
|
|
1551
|
-
* ```typescript
|
|
1552
|
-
* // Quartile split to find top 25%
|
|
1553
|
-
* db.user().select((u) => ({
|
|
1554
|
-
* name: u.name,
|
|
1555
|
-
* quartile: expr.ntile(4, {
|
|
1556
|
-
* orderBy: [[u.score, "DESC"]],
|
|
1557
|
-
* }),
|
|
1558
|
-
* }))
|
|
1559
|
-
* ```
|
|
1560
971
|
*/
|
|
1561
972
|
ntile(n, spec) {
|
|
1562
973
|
return new ExprUnit("number", {
|
|
@@ -1572,18 +983,6 @@ export const expr = {
|
|
|
1572
983
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1573
984
|
* @param options - offset (default 1), default (default value when no previous row)
|
|
1574
985
|
* @returns Previous row's value (or default value/NULL)
|
|
1575
|
-
*
|
|
1576
|
-
* @example
|
|
1577
|
-
* ```typescript
|
|
1578
|
-
* db.stock().select((s) => ({
|
|
1579
|
-
* date: s.date,
|
|
1580
|
-
* price: s.price,
|
|
1581
|
-
* prevPrice: expr.lag(s.price, {
|
|
1582
|
-
* partitionBy: [s.symbol],
|
|
1583
|
-
* orderBy: [[s.date, "ASC"]],
|
|
1584
|
-
* }),
|
|
1585
|
-
* }))
|
|
1586
|
-
* ```
|
|
1587
986
|
*/
|
|
1588
987
|
lag(column, spec, options) {
|
|
1589
988
|
return new ExprUnit(column.dataType, {
|
|
@@ -1604,18 +1003,6 @@ export const expr = {
|
|
|
1604
1003
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1605
1004
|
* @param options - offset (default 1), default (default value when no following row)
|
|
1606
1005
|
* @returns Following row's value (or default value/NULL)
|
|
1607
|
-
*
|
|
1608
|
-
* @example
|
|
1609
|
-
* ```typescript
|
|
1610
|
-
* db.stock().select((s) => ({
|
|
1611
|
-
* date: s.date,
|
|
1612
|
-
* price: s.price,
|
|
1613
|
-
* nextPrice: expr.lead(s.price, {
|
|
1614
|
-
* partitionBy: [s.symbol],
|
|
1615
|
-
* orderBy: [[s.date, "ASC"]],
|
|
1616
|
-
* }),
|
|
1617
|
-
* }))
|
|
1618
|
-
* ```
|
|
1619
1006
|
*/
|
|
1620
1007
|
lead(column, spec, options) {
|
|
1621
1008
|
return new ExprUnit(column.dataType, {
|
|
@@ -1635,17 +1022,6 @@ export const expr = {
|
|
|
1635
1022
|
* @param column - Column to reference
|
|
1636
1023
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1637
1024
|
* @returns First value
|
|
1638
|
-
*
|
|
1639
|
-
* @example
|
|
1640
|
-
* ```typescript
|
|
1641
|
-
* db.order().select((o) => ({
|
|
1642
|
-
* ...o,
|
|
1643
|
-
* firstOrderAmount: expr.firstValue(o.amount, {
|
|
1644
|
-
* partitionBy: [o.userId],
|
|
1645
|
-
* orderBy: [[o.createdAt, "ASC"]],
|
|
1646
|
-
* }),
|
|
1647
|
-
* }))
|
|
1648
|
-
* ```
|
|
1649
1025
|
*/
|
|
1650
1026
|
firstValue(column, spec) {
|
|
1651
1027
|
return new ExprUnit(column.dataType, {
|
|
@@ -1660,17 +1036,6 @@ export const expr = {
|
|
|
1660
1036
|
* @param column - Column to reference
|
|
1661
1037
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1662
1038
|
* @returns Last value
|
|
1663
|
-
*
|
|
1664
|
-
* @example
|
|
1665
|
-
* ```typescript
|
|
1666
|
-
* db.order().select((o) => ({
|
|
1667
|
-
* ...o,
|
|
1668
|
-
* lastOrderAmount: expr.lastValue(o.amount, {
|
|
1669
|
-
* partitionBy: [o.userId],
|
|
1670
|
-
* orderBy: [[o.createdAt, "ASC"]],
|
|
1671
|
-
* }),
|
|
1672
|
-
* }))
|
|
1673
|
-
* ```
|
|
1674
1039
|
*/
|
|
1675
1040
|
lastValue(column, spec) {
|
|
1676
1041
|
return new ExprUnit(column.dataType, {
|
|
@@ -1685,18 +1050,6 @@ export const expr = {
|
|
|
1685
1050
|
* @param column - Column to sum
|
|
1686
1051
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1687
1052
|
* @returns Sum within window
|
|
1688
|
-
*
|
|
1689
|
-
* @example
|
|
1690
|
-
* ```typescript
|
|
1691
|
-
* // Running total
|
|
1692
|
-
* db.order().select((o) => ({
|
|
1693
|
-
* ...o,
|
|
1694
|
-
* runningTotal: expr.sumOver(o.amount, {
|
|
1695
|
-
* partitionBy: [o.userId],
|
|
1696
|
-
* orderBy: [[o.createdAt, "ASC"]],
|
|
1697
|
-
* }),
|
|
1698
|
-
* }))
|
|
1699
|
-
* ```
|
|
1700
1053
|
*/
|
|
1701
1054
|
sumOver(column, spec) {
|
|
1702
1055
|
return new ExprUnit("number", {
|
|
@@ -1711,18 +1064,6 @@ export const expr = {
|
|
|
1711
1064
|
* @param column - Column to average
|
|
1712
1065
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1713
1066
|
* @returns Average within window
|
|
1714
|
-
*
|
|
1715
|
-
* @example
|
|
1716
|
-
* ```typescript
|
|
1717
|
-
* // Moving average
|
|
1718
|
-
* db.stock().select((s) => ({
|
|
1719
|
-
* ...s,
|
|
1720
|
-
* movingAvg: expr.avgOver(s.price, {
|
|
1721
|
-
* partitionBy: [s.symbol],
|
|
1722
|
-
* orderBy: [[s.date, "ASC"]],
|
|
1723
|
-
* }),
|
|
1724
|
-
* }))
|
|
1725
|
-
* ```
|
|
1726
1067
|
*/
|
|
1727
1068
|
avgOver(column, spec) {
|
|
1728
1069
|
return new ExprUnit("number", {
|
|
@@ -1737,16 +1078,6 @@ export const expr = {
|
|
|
1737
1078
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1738
1079
|
* @param column - Column to count (all rows if omitted)
|
|
1739
1080
|
* @returns Row count within window
|
|
1740
|
-
*
|
|
1741
|
-
* @example
|
|
1742
|
-
* ```typescript
|
|
1743
|
-
* db.order().select((o) => ({
|
|
1744
|
-
* ...o,
|
|
1745
|
-
* totalOrdersPerUser: expr.countOver({
|
|
1746
|
-
* partitionBy: [o.userId],
|
|
1747
|
-
* }),
|
|
1748
|
-
* }))
|
|
1749
|
-
* ```
|
|
1750
1081
|
*/
|
|
1751
1082
|
countOver(spec, column) {
|
|
1752
1083
|
return new ExprUnit("number", {
|
|
@@ -1761,16 +1092,6 @@ export const expr = {
|
|
|
1761
1092
|
* @param column - Column to find minimum of
|
|
1762
1093
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1763
1094
|
* @returns Minimum value within window
|
|
1764
|
-
*
|
|
1765
|
-
* @example
|
|
1766
|
-
* ```typescript
|
|
1767
|
-
* db.stock().select((s) => ({
|
|
1768
|
-
* ...s,
|
|
1769
|
-
* minPriceInPeriod: expr.minOver(s.price, {
|
|
1770
|
-
* partitionBy: [s.symbol],
|
|
1771
|
-
* }),
|
|
1772
|
-
* }))
|
|
1773
|
-
* ```
|
|
1774
1095
|
*/
|
|
1775
1096
|
minOver(column, spec) {
|
|
1776
1097
|
return new ExprUnit(column.dataType, {
|
|
@@ -1785,16 +1106,6 @@ export const expr = {
|
|
|
1785
1106
|
* @param column - Column to find maximum of
|
|
1786
1107
|
* @param spec - Window spec (partitionBy, orderBy)
|
|
1787
1108
|
* @returns Maximum value within window
|
|
1788
|
-
*
|
|
1789
|
-
* @example
|
|
1790
|
-
* ```typescript
|
|
1791
|
-
* db.stock().select((s) => ({
|
|
1792
|
-
* ...s,
|
|
1793
|
-
* maxPriceInPeriod: expr.maxOver(s.price, {
|
|
1794
|
-
* partitionBy: [s.symbol],
|
|
1795
|
-
* }),
|
|
1796
|
-
* }))
|
|
1797
|
-
* ```
|
|
1798
1109
|
*/
|
|
1799
1110
|
maxOver(column, spec) {
|
|
1800
1111
|
return new ExprUnit(column.dataType, {
|