11import assert from 'assert' ;
2+ import type { Knex } from 'knex' ;
23
34/**
45 * Supported SQL value types that can be safely parameterized.
@@ -12,7 +13,6 @@ export type SupportedSQLValue =
1213 | Date
1314 | Buffer
1415 | bigint
15- | undefined // Will be treated as NULL
1616 | readonly SupportedSQLValue [ ] // For IN clauses and array types
1717 | Readonly < { [ key : string ] : unknown } > ; // For JSON/JSONB columns
1818
@@ -41,15 +41,18 @@ export class SQLFragment<TFields extends Record<string, any>> {
4141 */
4242 getKnexBindings (
4343 getColumnForField : ( fieldName : keyof TFields ) => string ,
44- ) : readonly SupportedSQLValue [ ] {
44+ ) : readonly Knex . RawBinding [ ] {
4545 return this . bindings . map ( ( b ) => {
4646 switch ( b . type ) {
4747 case 'entityField' :
4848 return getColumnForField ( b . fieldName ) ;
4949 case 'identifier' :
5050 return b . name ;
5151 case 'value' :
52- return b . value ;
52+ // Needs a cast since bigint is supported by knex postgres dialect but not all dialects, and thus isn't included
53+ // in the type. Because we only use the postgres dialect in this adapter, it's safe to allow it here.
54+ // https://github.com/knex/knex/issues/5013#issuecomment-3368744254
55+ return b . value as Knex . RawBinding ;
5356 }
5457 } ) ;
5558 }
@@ -133,8 +136,8 @@ export class SQLFragment<TFields extends Record<string, any>> {
133136 * Handles all SupportedSQLValue types.
134137 */
135138 private static formatDebugValue ( value : SupportedSQLValue ) : string {
136- // Handle null and undefined
137- if ( value === null || value === undefined ) {
139+ // Handle null
140+ if ( value === null ) {
138141 return 'NULL' ;
139142 }
140143
@@ -303,7 +306,7 @@ export function sql<TFields extends Record<string, any>>(
303306 strings . forEach ( ( string , i ) => {
304307 sqlString += string ;
305308 if ( i < values . length ) {
306- const value = values [ i ] ;
309+ const value = values [ i ] ! ;
307310
308311 if ( value instanceof SQLFragment ) {
309312 // Handle nested SQL fragments
@@ -344,7 +347,7 @@ type PickSupportedSQLValueKeys<T> = {
344347} [ keyof T ] ;
345348
346349type PickStringValueKeys < T > = {
347- [ K in keyof T ] : T [ K ] extends string | null | undefined ? K : never ;
350+ [ K in keyof T ] : T [ K ] extends string | null ? K : never ;
348351} [ keyof T ] ;
349352
350353type JsonSerializable =
@@ -368,27 +371,27 @@ export class SQLChainableFragment<
368371> extends SQLFragment < TFields > {
369372 /**
370373 * Generates an equality condition (`= value`).
371- * Automatically converts `null`/`undefined` to `IS NULL`.
374+ * Automatically converts `null` to `IS NULL`.
372375 *
373376 * @param value - The value to compare against
374377 * @returns A {@link SQLFragment} representing the equality condition
375378 */
376- eq ( value : TValue | null | undefined ) : SQLFragment < TFields > {
377- if ( value === null || value === undefined ) {
379+ eq ( value : TValue | null ) : SQLFragment < TFields > {
380+ if ( value === null ) {
378381 return this . isNull ( ) ;
379382 }
380383 return sql `${ this } = ${ value } ` ;
381384 }
382385
383386 /**
384387 * Generates an inequality condition (`!= value`).
385- * Automatically converts `null`/`undefined` to `IS NOT NULL`.
388+ * Automatically converts `null` to `IS NOT NULL`.
386389 *
387390 * @param value - The value to compare against
388391 * @returns A {@link SQLFragment} representing the inequality condition
389392 */
390- neq ( value : TValue | null | undefined ) : SQLFragment < TFields > {
391- if ( value === null || value === undefined ) {
393+ neq ( value : TValue | null ) : SQLFragment < TFields > {
394+ if ( value === null ) {
392395 return this . isNotNull ( ) ;
393396 }
394397 return sql `${ this } != ${ value } ` ;
@@ -635,9 +638,7 @@ type ExtractFragmentFields<T> = T extends SQLFragment<infer F> ? F : never;
635638// Conditional value types for expression overloads.
636639// Uses SQLChainableFragment<any, ...> so that TExpr alone drives inference (single type param).
637640type FragmentValueNullable < TFragment > =
638- TFragment extends SQLChainableFragment < any , infer TValue >
639- ? TValue | null | undefined
640- : SupportedSQLValue ;
641+ TFragment extends SQLChainableFragment < any , infer TValue > ? TValue | null : SupportedSQLValue ;
641642
642643type FragmentValue < TFragment > =
643644 TFragment extends SQLChainableFragment < any , infer TValue > ? TValue : SupportedSQLValue ;
@@ -950,7 +951,7 @@ function isNotNullHelper<TFields extends Record<string, any>>(
950951
951952/**
952953 * Generates an equality condition (`= value`) from a fragment.
953- * Automatically converts `null`/`undefined` to `IS NULL`.
954+ * Automatically converts `null` to `IS NULL`.
954955 *
955956 * @param fragment - A SQLFragment or SQLChainableFragment to compare
956957 * @param value - The value to compare against
@@ -961,7 +962,7 @@ function eqHelper<TFragment extends SQLFragment<any>>(
961962) : SQLFragment < ExtractFragmentFields < TFragment > > ;
962963/**
963964 * Generates an equality condition (`= value`) from a field name.
964- * Automatically converts `null`/`undefined` to `IS NULL`.
965+ * Automatically converts `null` to `IS NULL`.
965966 *
966967 * @param fieldName - The entity field name to compare
967968 * @param value - The value to compare against
@@ -979,7 +980,7 @@ function eqHelper<TFields extends Record<string, any>>(
979980
980981/**
981982 * Generates an inequality condition (`!= value`) from a fragment.
982- * Automatically converts `null`/`undefined` to `IS NOT NULL`.
983+ * Automatically converts `null` to `IS NOT NULL`.
983984 *
984985 * @param fragment - A SQLFragment or SQLChainableFragment to compare
985986 * @param value - The value to compare against
@@ -990,7 +991,7 @@ function neqHelper<TFragment extends SQLFragment<any>>(
990991) : SQLFragment < ExtractFragmentFields < TFragment > > ;
991992/**
992993 * Generates an inequality condition (`!= value`) from a field name.
993- * Automatically converts `null`/`undefined` to `IS NOT NULL`.
994+ * Automatically converts `null` to `IS NOT NULL`.
994995 *
995996 * @param fieldName - The entity field name to compare
996997 * @param value - The value to compare against
@@ -1521,12 +1522,12 @@ export const SQLExpression = {
15211522 isNotNull : isNotNullHelper ,
15221523
15231524 /**
1524- * Equality operator. Automatically converts null/undefined to IS NULL.
1525+ * Equality operator. Automatically converts null to IS NULL.
15251526 */
15261527 eq : eqHelper ,
15271528
15281529 /**
1529- * Inequality operator. Automatically converts null/undefined to IS NOT NULL.
1530+ * Inequality operator. Automatically converts null to IS NOT NULL.
15301531 */
15311532 neq : neqHelper ,
15321533
0 commit comments