Skip to content

Commit f44031d

Browse files
committed
checkpoint
1 parent 2fb394f commit f44031d

File tree

4 files changed

+224
-86
lines changed

4 files changed

+224
-86
lines changed

packages/db/src/query/builder/functions.ts

Lines changed: 132 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ export function not(value: ExpressionLike): BasicExpression<boolean> {
121121
return new Func(`not`, [toExpression(value)])
122122
}
123123

124+
// Null/undefined checking functions
125+
export function isUndefined(value: ExpressionLike): BasicExpression<boolean> {
126+
return new Func(`isUndefined`, [toExpression(value)])
127+
}
128+
129+
export function isNotUndefined(value: ExpressionLike): BasicExpression<boolean> {
130+
return new Func(`isNotUndefined`, [toExpression(value)])
131+
}
132+
133+
export function isNull(value: ExpressionLike): BasicExpression<boolean> {
134+
return new Func(`isNull`, [toExpression(value)])
135+
}
136+
137+
export function isNotNull(value: ExpressionLike): BasicExpression<boolean> {
138+
return new Func(`isNotNull`, [toExpression(value)])
139+
}
140+
124141
export function inArray(
125142
value: ExpressionLike,
126143
array: ExpressionLike
@@ -134,8 +151,25 @@ export function like(
134151
| RefProxy<string | null>
135152
| RefProxy<string | undefined>
136153
| string
137-
| BasicExpression<string>,
138-
right: string | RefProxy<string> | BasicExpression<string>
154+
| string | null
155+
| string | undefined
156+
| BasicExpression<string>
157+
| BasicExpression<string | null>
158+
| BasicExpression<string | undefined>
159+
| null
160+
| undefined,
161+
right:
162+
| string
163+
| string | null
164+
| string | undefined
165+
| RefProxy<string>
166+
| RefProxy<string | null>
167+
| RefProxy<string | undefined>
168+
| BasicExpression<string>
169+
| BasicExpression<string | null>
170+
| BasicExpression<string | undefined>
171+
| null
172+
| undefined
139173
): BasicExpression<boolean>
140174
export function like(left: any, right: any): BasicExpression<boolean> {
141175
return new Func(`like`, [toExpression(left), toExpression(right)])
@@ -147,8 +181,25 @@ export function ilike(
147181
| RefProxy<string | null>
148182
| RefProxy<string | undefined>
149183
| string
150-
| BasicExpression<string>,
151-
right: string | RefProxy<string> | BasicExpression<string>
184+
| string | null
185+
| string | undefined
186+
| BasicExpression<string>
187+
| BasicExpression<string | null>
188+
| BasicExpression<string | undefined>
189+
| null
190+
| undefined,
191+
right:
192+
| string
193+
| string | null
194+
| string | undefined
195+
| RefProxy<string>
196+
| RefProxy<string | null>
197+
| RefProxy<string | undefined>
198+
| BasicExpression<string>
199+
| BasicExpression<string | null>
200+
| BasicExpression<string | undefined>
201+
| null
202+
| undefined
152203
): BasicExpression<boolean> {
153204
return new Func(`ilike`, [toExpression(left), toExpression(right)])
154205
}
@@ -159,33 +210,59 @@ export function upper(
159210
arg:
160211
| RefProxy<string>
161212
| RefProxy<string | undefined>
213+
| RefProxy<string | null>
162214
| string
215+
| string | undefined
216+
| string | null
163217
| BasicExpression<string>
164-
): BasicExpression<string> {
218+
| BasicExpression<string | undefined>
219+
| BasicExpression<string | null>
220+
| undefined
221+
| null
222+
): BasicExpression<string | undefined | null> {
165223
return new Func(`upper`, [toExpression(arg)])
166224
}
167225

168226
export function lower(
169227
arg:
170228
| RefProxy<string>
171229
| RefProxy<string | undefined>
230+
| RefProxy<string | null>
172231
| string
232+
| string | undefined
233+
| string | null
173234
| BasicExpression<string>
174-
): BasicExpression<string> {
235+
| BasicExpression<string | undefined>
236+
| BasicExpression<string | null>
237+
| undefined
238+
| null
239+
): BasicExpression<string | undefined | null> {
175240
return new Func(`lower`, [toExpression(arg)])
176241
}
177242

178243
export function length(
179244
arg:
180245
| RefProxy<string>
181246
| RefProxy<string | undefined>
247+
| RefProxy<string | null>
182248
| RefProxy<Array<any>>
183249
| RefProxy<Array<any> | undefined>
250+
| RefProxy<Array<any> | null>
184251
| string
252+
| string | undefined
253+
| string | null
185254
| Array<any>
255+
| Array<any> | undefined
256+
| Array<any> | null
186257
| BasicExpression<string>
258+
| BasicExpression<string | undefined>
259+
| BasicExpression<string | null>
187260
| BasicExpression<Array<any>>
188-
): BasicExpression<number> {
261+
| BasicExpression<Array<any> | undefined>
262+
| BasicExpression<Array<any> | null>
263+
| undefined
264+
| null
265+
): BasicExpression<number | undefined | null> {
189266
return new Func(`length`, [toExpression(arg)])
190267
}
191268

@@ -209,14 +286,28 @@ export function add(
209286
left:
210287
| RefProxy<number>
211288
| RefProxy<number | undefined>
289+
| RefProxy<number | null>
212290
| number
213-
| BasicExpression<number>,
291+
| number | undefined
292+
| number | null
293+
| BasicExpression<number>
294+
| BasicExpression<number | undefined>
295+
| BasicExpression<number | null>
296+
| undefined
297+
| null,
214298
right:
215299
| RefProxy<number>
216300
| RefProxy<number | undefined>
301+
| RefProxy<number | null>
217302
| number
303+
| number | undefined
304+
| number | null
218305
| BasicExpression<number>
219-
): BasicExpression<number> {
306+
| BasicExpression<number | undefined>
307+
| BasicExpression<number | null>
308+
| undefined
309+
| null
310+
): BasicExpression<number | undefined | null> {
220311
return new Func(`add`, [toExpression(left), toExpression(right)])
221312
}
222313

@@ -230,39 +321,67 @@ export function avg(
230321
arg:
231322
| RefProxy<number>
232323
| RefProxy<number | undefined>
324+
| RefProxy<number | null>
233325
| number
326+
| number | undefined
327+
| number | null
234328
| BasicExpression<number>
235-
): Aggregate<number> {
329+
| BasicExpression<number | undefined>
330+
| BasicExpression<number | null>
331+
| undefined
332+
| null
333+
): Aggregate<number | undefined | null> {
236334
return new Aggregate(`avg`, [toExpression(arg)])
237335
}
238336

239337
export function sum(
240338
arg:
241339
| RefProxy<number>
242340
| RefProxy<number | undefined>
341+
| RefProxy<number | null>
243342
| number
343+
| number | undefined
344+
| number | null
244345
| BasicExpression<number>
245-
): Aggregate<number> {
346+
| BasicExpression<number | undefined>
347+
| BasicExpression<number | null>
348+
| undefined
349+
| null
350+
): Aggregate<number | undefined | null> {
246351
return new Aggregate(`sum`, [toExpression(arg)])
247352
}
248353

249354
export function min(
250355
arg:
251356
| RefProxy<number>
252357
| RefProxy<number | undefined>
358+
| RefProxy<number | null>
253359
| number
360+
| number | undefined
361+
| number | null
254362
| BasicExpression<number>
255-
): Aggregate<number> {
363+
| BasicExpression<number | undefined>
364+
| BasicExpression<number | null>
365+
| undefined
366+
| null
367+
): Aggregate<number | undefined | null> {
256368
return new Aggregate(`min`, [toExpression(arg)])
257369
}
258370

259371
export function max(
260372
arg:
261373
| RefProxy<number>
262374
| RefProxy<number | undefined>
375+
| RefProxy<number | null>
263376
| number
377+
| number | undefined
378+
| number | null
264379
| BasicExpression<number>
265-
): Aggregate<number> {
380+
| BasicExpression<number | undefined>
381+
| BasicExpression<number | null>
382+
| undefined
383+
| null
384+
): Aggregate<number | undefined | null> {
266385
return new Aggregate(`max`, [toExpression(arg)])
267386
}
268387

packages/db/src/query/builder/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,10 @@ export class BaseQueryBuilder<TContext extends Context = Context> {
432432

433433
// Then add the explicit select fields
434434
for (const [key, value] of Object.entries(selectObject)) {
435-
if (isRefProxy(value)) {
435+
if (value === undefined) {
436+
// Handle undefined values from optional chaining
437+
select[key] = toExpression(null) // Convert undefined to null for SQL compatibility
438+
} else if (isRefProxy(value)) {
436439
select[key] = toExpression(value)
437440
} else if (
438441
typeof value === `object` &&

0 commit comments

Comments
 (0)