@@ -24,6 +24,7 @@ import { MetadataTableBase } from "../metadata-table-base";
2424import { ProjectionCompile } from "../crud/projection-compile" ;
2525import * as lodash from "lodash" ;
2626import { QueryCompiled } from "." ;
27+ import { Resultable } from "./resultable" ;
2728
2829export type ParamType = ValueType | ReplacementParam ;
2930
@@ -169,6 +170,13 @@ export class Utils {
169170 return instance instanceof PlanRef ;
170171 }
171172
173+ public static isResultable ( instance : any ) : instance is Resultable {
174+ return instance
175+ && this . isObject ( instance )
176+ && "result" in instance
177+ && this . isFunction ( instance . result ) ;
178+ }
179+
172180 public static isEmpty ( value : any ) : boolean {
173181 if ( this . isBoolean ( value ) || this . isDate ( value ) ) {
174182 return this . isNull ( value ) ;
@@ -247,13 +255,14 @@ export class Utils {
247255 params : [ ]
248256 } ;
249257 case ( ExpressionOrValueEnum . Ref ) :
250- return {
251- column : ( expression as ColumnRef ) . result ( ) ,
252- params : [ ]
253- } ;
258+ // return {
259+ // column: (expression as ColumnRef).result(),
260+ // params: []
261+ // };
254262 case ( ExpressionOrValueEnum . Plan ) :
255263 return {
256- column : ( expression as PlanRef ) . result ( ) ,
264+ // column: (expression as PlanRef).result(),
265+ column : expression as Resultable ,
257266 params : [ ]
258267 } ;
259268 case ( ExpressionOrValueEnum . Value ) :
@@ -381,12 +390,15 @@ export class Utils {
381390 }
382391
383392 public static addAlias (
384- column : string , alias : string
393+ column : string | Resultable , alias : string
385394 ) : string {
386- if ( column && alias && Utils . isNameColumn ( column ) ) {
395+ if ( this . isResultable ( column ) ) {
396+ return ( column as Resultable ) . result ( ) ;
397+ }
398+ if ( column && alias && Utils . isNameColumn ( column as string ) ) {
387399 return `${ alias } .${ column } ` ;
388400 }
389- return column ;
401+ return column as string ;
390402 }
391403
392404 private static isColumnReservedNameOrNotAllowed ( columnName : string ) : boolean {
0 commit comments