Skip to content

Commit efa4b13

Browse files
committed
checkpoint
1 parent 3b26333 commit efa4b13

File tree

8 files changed

+119
-109
lines changed

8 files changed

+119
-109
lines changed

packages/db/tests/query/functional-variants.test-d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,11 @@ describe(`Functional Variants Types`, () => {
450450
.join({ dept: departmentsCollection }, ({ user, dept }) =>
451451
eq(user.department_id, dept.id)
452452
)
453-
.groupBy(({ dept }) => dept.name)
453+
.groupBy(({ dept }) => dept?.name)
454454
.fn.having((row) => row.dept?.name !== `HR`)
455455
.select(({ dept, user }) => ({
456-
departmentId: dept.id,
457-
departmentName: dept.name,
456+
departmentId: dept?.id,
457+
departmentName: dept?.name,
458458
totalEmployees: count(user.id),
459459
})),
460460
})

packages/db/tests/query/group-by.test.ts

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
min,
1515
or,
1616
sum,
17+
isNotUndefined,
18+
coalesce,
1719
} from "../../src/query/builder/functions.js"
1820

1921
// Sample data types for comprehensive GROUP BY testing
@@ -1062,10 +1064,10 @@ function createGroupByTests(autoIndex: `off` | `eager`): void {
10621064
query: (q) =>
10631065
q
10641066
.from({ orders: ordersCollection })
1065-
.where(({ orders }) => orders.customer !== undefined)
1066-
.groupBy(({ orders }) => orders.customer.tier)
1067+
.where(({ orders }) => isNotUndefined(orders.customer))
1068+
.groupBy(({ orders }) => orders.customer?.tier)
10671069
.select(({ orders }) => ({
1068-
tier: orders.customer.tier,
1070+
tier: orders.customer?.tier,
10691071
order_count: count(orders.id),
10701072
total_amount: sum(orders.amount),
10711073
avg_amount: avg(orders.amount),
@@ -1092,13 +1094,13 @@ function createGroupByTests(autoIndex: `off` | `eager`): void {
10921094
query: (q) =>
10931095
q
10941096
.from({ orders: ordersCollection })
1095-
.where(({ orders }) => orders.customer.address !== undefined)
1096-
.groupBy(({ orders }) => orders.customer.address.state)
1097+
.where(({ orders }) => isNotUndefined(orders.customer?.address))
1098+
.groupBy(({ orders }) => orders.customer?.address?.state)
10971099
.select(({ orders }) => ({
1098-
state: orders.customer.address.state,
1100+
state: orders.customer?.address?.state,
10991101
order_count: count(orders.id),
11001102
total_amount: sum(orders.amount),
1101-
cities: orders.customer.address.city,
1103+
cities: orders.customer?.address?.city,
11021104
})),
11031105
})
11041106

@@ -1122,14 +1124,14 @@ function createGroupByTests(autoIndex: `off` | `eager`): void {
11221124
query: (q) =>
11231125
q
11241126
.from({ orders: ordersCollection })
1125-
.where(({ orders }) => orders.shipping !== undefined)
1126-
.groupBy(({ orders }) => orders.shipping.method)
1127+
.where(({ orders }) => isNotUndefined(orders.shipping))
1128+
.groupBy(({ orders }) => orders.shipping?.method)
11271129
.select(({ orders }) => ({
1128-
method: orders.shipping.method,
1130+
method: orders.shipping?.method,
11291131
order_count: count(orders.id),
11301132
total_amount: sum(orders.amount),
1131-
avg_shipping_cost: avg(orders.shipping.cost),
1132-
total_shipping_cost: sum(orders.shipping.cost),
1133+
avg_shipping_cost: avg(orders.shipping?.cost),
1134+
total_shipping_cost: sum(orders.shipping?.cost),
11331135
})),
11341136
})
11351137

@@ -1157,15 +1159,15 @@ function createGroupByTests(autoIndex: `off` | `eager`): void {
11571159
.from({ orders: ordersCollection })
11581160
.where(({ orders }) =>
11591161
and(
1160-
orders.customer !== undefined,
1161-
orders.shipping !== undefined
1162+
isNotUndefined(orders.customer),
1163+
isNotUndefined(orders.shipping)
11621164
)
11631165
)
1164-
.groupBy(({ orders }) => orders.customer.tier)
1165-
.groupBy(({ orders }) => orders.shipping.method)
1166+
.groupBy(({ orders }) => orders.customer?.tier)
1167+
.groupBy(({ orders }) => orders.shipping?.method)
11661168
.select(({ orders }) => ({
1167-
tier: orders.customer.tier,
1168-
method: orders.shipping.method,
1169+
tier: orders.customer?.tier,
1170+
method: orders.shipping?.method,
11691171
order_count: count(orders.id),
11701172
total_amount: sum(orders.amount),
11711173
})),
@@ -1196,10 +1198,12 @@ function createGroupByTests(autoIndex: `off` | `eager`): void {
11961198
query: (q) =>
11971199
q
11981200
.from({ orders: ordersCollection })
1199-
.where(({ orders }) => orders.customer.preferences !== undefined)
1200-
.groupBy(({ orders }) => orders.customer.preferences.newsletter)
1201+
.where(({ orders }) =>
1202+
isNotUndefined(orders.customer?.preferences)
1203+
)
1204+
.groupBy(({ orders }) => orders.customer?.preferences?.newsletter)
12011205
.select(({ orders }) => ({
1202-
newsletter_subscribed: orders.customer.preferences.newsletter,
1206+
newsletter_subscribed: orders.customer?.preferences?.newsletter,
12031207
order_count: count(orders.id),
12041208
total_amount: sum(orders.amount),
12051209
avg_amount: avg(orders.amount),
@@ -1231,16 +1235,22 @@ function createGroupByTests(autoIndex: `off` | `eager`): void {
12311235
q
12321236
.from({ orders: ordersCollection })
12331237
.groupBy(({ orders }) =>
1234-
orders.shipping.tracking !== undefined ? `tracked` : `untracked`
1238+
coalesce(
1239+
isNotUndefined(orders.shipping?.tracking),
1240+
`tracked`,
1241+
`untracked`
1242+
)
12351243
)
12361244
.select(({ orders }) => ({
12371245
tracking_status:
1238-
orders.shipping.tracking !== undefined
1239-
? `tracked`
1240-
: `untracked`,
1246+
coalesce(
1247+
isNotUndefined(orders.shipping?.tracking),
1248+
`tracked`,
1249+
`untracked`
1250+
),
12411251
order_count: count(orders.id),
12421252
total_amount: sum(orders.amount),
1243-
has_tracking: orders.shipping.tracking !== undefined,
1253+
has_tracking: isNotUndefined(orders.shipping?.tracking),
12441254
})),
12451255
})
12461256

@@ -1263,10 +1273,10 @@ function createGroupByTests(autoIndex: `off` | `eager`): void {
12631273
query: (q) =>
12641274
q
12651275
.from({ orders: ordersCollection })
1266-
.where(({ orders }) => orders.customer !== undefined)
1267-
.groupBy(({ orders }) => orders.customer.tier)
1276+
.where(({ orders }) => isNotUndefined(orders.customer))
1277+
.groupBy(({ orders }) => orders.customer?.tier)
12681278
.select(({ orders }) => ({
1269-
tier: orders.customer.tier,
1279+
tier: orders.customer?.tier,
12701280
order_count: count(orders.id),
12711281
total_amount: sum(orders.amount),
12721282
})),

packages/db/tests/query/join-subquery.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ describe(`Join Subquery Types`, () => {
386386
)
387387
.select(({ issue, activeUser }) => ({
388388
issue_title: issue.title,
389-
user_name: activeUser.name, // Should now be string | undefined
389+
user_name: activeUser?.name, // Should now be string | undefined
390390
issue_status: issue.status,
391391
}))
392392
},

packages/db/tests/query/join-subquery.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function createJoinSubqueryTests(autoIndex: `off` | `eager`): void {
193193
)
194194
.select(({ issue, activeUser }) => ({
195195
issue_title: issue.title,
196-
user_name: activeUser.name,
196+
user_name: activeUser?.name,
197197
issue_status: issue.status,
198198
}))
199199
},
@@ -333,8 +333,8 @@ function createJoinSubqueryTests(autoIndex: `off` | `eager`): void {
333333
.select(({ issue, activeUser }) => ({
334334
issue_title: issue.title,
335335
issue_status: issue.status,
336-
user_name: activeUser.name,
337-
user_status: activeUser.status,
336+
user_name: activeUser?.name,
337+
user_status: activeUser?.status,
338338
}))
339339
},
340340
})

packages/db/tests/query/join.test-d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ describe(`Join Types - Type Safety`, () => {
209209
)
210210
.select(({ user, dept }) => ({
211211
userName: user.name,
212-
deptName: dept.name, // This should still be accessible in select
213-
deptBudget: dept.budget,
212+
deptName: dept?.name, // This should still be accessible in select
213+
deptBudget: dept?.budget,
214214
})),
215215
})
216216

@@ -383,8 +383,8 @@ describe(`Join Alias Methods - Type Safety`, () => {
383383
)
384384
.select(({ user, dept }) => ({
385385
userName: user.name,
386-
deptName: dept.name, // This should be string | undefined due to left join
387-
deptBudget: dept.budget,
386+
deptName: dept?.name, // This should be string | undefined due to left join
387+
deptBudget: dept?.budget,
388388
})),
389389
})
390390

@@ -457,7 +457,7 @@ describe(`Join Alias Methods - Type Safety`, () => {
457457
)
458458
.join(
459459
{ project: projectsCollection },
460-
({ dept, project }) => eq(dept.id, project.department_id),
460+
({ dept, project }) => eq(dept?.id, project.department_id),
461461
`inner`
462462
),
463463
})
@@ -687,7 +687,7 @@ describe(`Join Alias Methods - Type Safety`, () => {
687687
)
688688
.select(({ post, user }) => ({
689689
postTitle: post.title,
690-
authorName: user.name, // This will be string | undefined due to left join
690+
authorName: user?.name, // This will be string | undefined due to left join
691691
})),
692692
})
693693

@@ -835,7 +835,7 @@ describe(`Join with ArkType Schemas`, () => {
835835
)
836836
.select(({ post, user }) => ({
837837
postTitle: post.title,
838-
authorName: user.name, // This will be string | undefined due to left join
838+
authorName: user?.name, // This will be string | undefined due to left join
839839
})),
840840
})
841841

packages/db/tests/query/join.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ function testJoinType(joinType: JoinType, autoIndex: `off` | `eager`) {
108108
joinType
109109
)
110110
.select(({ user, dept }) => ({
111-
user_name: user.name,
112-
department_name: dept.name,
113-
budget: dept.budget,
111+
user_name: user?.name,
112+
department_name: dept?.name,
113+
budget: dept?.budget,
114114
})),
115115
})
116116

@@ -289,8 +289,8 @@ function testJoinType(joinType: JoinType, autoIndex: `off` | `eager`) {
289289
joinType
290290
)
291291
.select(({ user, dept }) => ({
292-
user_name: user.name,
293-
department_name: dept.name,
292+
user_name: user?.name,
293+
department_name: dept?.name,
294294
})),
295295
})
296296

@@ -332,8 +332,8 @@ function testJoinType(joinType: JoinType, autoIndex: `off` | `eager`) {
332332
joinType
333333
)
334334
.select(({ user, dept }) => ({
335-
user_name: user.name,
336-
department_name: dept.name,
335+
user_name: user?.name,
336+
department_name: dept?.name,
337337
})),
338338
})
339339

@@ -371,8 +371,8 @@ function testJoinType(joinType: JoinType, autoIndex: `off` | `eager`) {
371371
joinType
372372
)
373373
.select(({ user, dept }) => ({
374-
user_name: user.name,
375-
department_name: dept.name,
374+
user_name: user?.name,
375+
department_name: dept?.name,
376376
})),
377377
})
378378

@@ -420,8 +420,8 @@ function testJoinType(joinType: JoinType, autoIndex: `off` | `eager`) {
420420
joinType
421421
)
422422
.select(({ user, dept }) => ({
423-
user_name: user.name,
424-
department_name: dept.name,
423+
user_name: user?.name,
424+
department_name: dept?.name,
425425
})),
426426
})
427427

@@ -486,8 +486,8 @@ function createJoinTests(autoIndex: `off` | `eager`): void {
486486
`inner`
487487
)
488488
.select(({ user, dept }) => ({
489-
user_name: user.name,
490-
department_name: dept.name,
489+
user_name: user?.name,
490+
department_name: dept?.name,
491491
})),
492492
})
493493

@@ -561,8 +561,8 @@ function createJoinTests(autoIndex: `off` | `eager`): void {
561561
`inner`
562562
)
563563
.select(({ user, dept }) => ({
564-
user_name: user.name,
565-
department_name: dept.name,
564+
user_name: user?.name,
565+
department_name: dept?.name,
566566
})),
567567
})
568568

@@ -601,9 +601,9 @@ function createJoinTests(autoIndex: `off` | `eager`): void {
601601
)
602602
.select(({ user, dept }) => ({
603603
user_id: user.id,
604-
user_name: user.name,
605-
department_id: user.department_id,
606-
department_name: dept.name,
604+
user_name: user?.name,
605+
department_id: user?.department_id,
606+
department_name: dept?.name,
607607
})),
608608
})
609609

0 commit comments

Comments
 (0)