@@ -62,7 +62,23 @@ function getColumnExpression(field_def: ObjectField, collection_alias: string, c
62
62
return processType ( field_def . type ) ;
63
63
}
64
64
65
- function isTimestampType ( field_def : any ) : boolean {
65
+ function isStringType ( field_def : ObjectField | undefined ) : boolean {
66
+ if ( ! field_def ) return false ;
67
+
68
+ function checkType ( type : any ) : boolean {
69
+ if ( type . type === "nullable" ) {
70
+ return checkType ( type . underlying_type ) ;
71
+ }
72
+ if ( type . type === "array" ) {
73
+ return false ;
74
+ }
75
+ return type . type === "named" && type . name === "String" ;
76
+ }
77
+
78
+ return checkType ( field_def . type ) ;
79
+ }
80
+
81
+ function isTimestampType ( field_def : ObjectField | undefined ) : boolean {
66
82
if ( ! field_def ) return false ;
67
83
68
84
function checkType ( type : any ) : boolean {
@@ -74,7 +90,7 @@ function isTimestampType(field_def: any): boolean {
74
90
75
91
return checkType ( field_def . type ) ;
76
92
}
77
- function getIntegerType ( field_def : any ) : string | null {
93
+ function getIntegerType ( field_def : ObjectField | undefined ) : string | null {
78
94
if ( ! field_def ) return null ;
79
95
80
96
function checkType ( type : any ) : string | null {
@@ -411,11 +427,16 @@ function build_query(
411
427
switch ( elem . target . type ) {
412
428
case "column" :
413
429
if ( elem . target . path . length === 0 ) {
430
+ const field_def = config . config . object_types [ query_request . collection ] . fields [ elem . target . name ] ;
431
+ const is_string = isStringType ( field_def ) ;
432
+ const field_name = is_string ? `LOWER(${ escape_double ( collection_alias ) } .${ escape_double ( elem . target . name ) } )` : `${ escape_double ( collection_alias ) } .${ escape_double ( elem . target . name ) } `
414
433
order_elems . push (
415
- `LOWER( ${ escape_double ( collection_alias ) } . ${ escape_double ( elem . target . name ) } ) ${ elem . order_direction } `
434
+ `${ field_name } ${ elem . order_direction } `
416
435
) ;
417
436
} else {
418
437
let currentAlias = collection_alias ;
438
+ let current_collection = query_request . collection ;
439
+ let field_def = config . config . object_types [ current_collection ] . fields [ elem . target . name ] ;
419
440
for ( let path_elem of elem . target . path ) {
420
441
const relationship = collection_relationships [ path_elem . relationship ] ;
421
442
const nextAlias = `${ currentAlias } _${ relationship . target_collection } ` ;
@@ -425,9 +446,13 @@ function build_query(
425
446
filter_joins . push ( join_str ) ;
426
447
}
427
448
currentAlias = nextAlias ;
449
+ current_collection = relationship . target_collection ;
450
+ field_def = config . config . object_types [ current_collection ] . fields [ elem . target . name ] ;
428
451
}
452
+ const is_string = isStringType ( field_def ) ;
453
+ const field_name = is_string ? `LOWER(${ escape_double ( currentAlias ) } .${ escape_double ( elem . target . name ) } )` : `${ escape_double ( currentAlias ) } .${ escape_double ( elem . target . name ) } ` ;
429
454
order_elems . push (
430
- `${ escape_double ( currentAlias ) } . ${ escape_double ( elem . target . name ) } ${ elem . order_direction } `
455
+ `${ field_name } ${ elem . order_direction } `
431
456
) ;
432
457
}
433
458
break ;
@@ -569,6 +594,7 @@ export async function do_query(
569
594
state : State ,
570
595
query : QueryRequest
571
596
) : Promise < QueryResponse > {
597
+ // console.log(JSON.stringify(query, null, 4));
572
598
let query_plans = await plan_queries ( configuration , query ) ;
573
599
return await perform_query ( state , query_plans ) ;
574
600
}
0 commit comments