File tree Expand file tree Collapse file tree 5 files changed +15
-12
lines changed Expand file tree Collapse file tree 5 files changed +15
-12
lines changed Original file line number Diff line number Diff line change 11var soqlParserJs = require ( '../dist' ) ;
22
33const query = `
4- SELECT COUNT_DISTINCT(Company) FROM Lead
4+ SELECT Id, c.FirstName, c.LastName
5+ FROM Contact c
6+ LIMIT 1
57` ;
68
79const parsedQuery = soqlParserJs . parseQuery ( query , { logging : true } ) ;
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ export class Compose {
6969
7070 private parseQuery ( query : Query , isSubquery : boolean = false ) : string {
7171 const fieldData : FieldData = {
72- fields : this . parseFields ( query . fields , query . sObjectAlias ? true : false ) . map ( field => ( {
72+ fields : this . parseFields ( query . fields ) . map ( field => ( {
7373 text : field ,
7474 isSubquery : false ,
7575 prefix : '' ,
@@ -170,12 +170,12 @@ export class Compose {
170170 return output ;
171171 }
172172
173- private parseFields ( fields : Field [ ] , hasSObjectAlias : boolean ) : string [ ] {
173+ private parseFields ( fields : Field [ ] ) : string [ ] {
174174 return fields
175175 . map ( field => {
176176 if ( utils . isString ( field . text ) ) {
177- if ( hasSObjectAlias ) {
178- return `${ utils . get ( field . alias , '.' ) } ${ field . text } ` ;
177+ if ( field . objectPrefix ) {
178+ return `${ utils . get ( field . objectPrefix , '.' ) } ${ field . text } ` ;
179179 } else {
180180 return `${ field . text } ${ utils . get ( field . alias , '' , ' ' ) } ` ;
181181 }
Original file line number Diff line number Diff line change @@ -215,7 +215,7 @@ export class Listener implements SOQLListener {
215215 // All fields need to update to remove the alias from relationships
216216 this . getSoqlQuery ( ) . fields . forEach ( field => {
217217 if ( field . text && field . text . startsWith ( `${ ctx . text } .` ) ) {
218- field . alias = ctx . text ;
218+ field . objectPrefix = ctx . text ;
219219 field . text = field . text . replace ( `${ ctx . text } .` , '' ) ;
220220 if ( field . relationshipFields . length > 2 ) {
221221 field . relationshipFields = field . relationshipFields . splice ( 1 ) ;
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ export interface SelectStatement {
3131export interface Field {
3232 text ?: string ;
3333 alias ?: string ;
34+ objectPrefix ?: string ;
3435 relationshipFields ?: string [ ] ;
3536 fn ?: FunctionExp ;
3637 subqueryObjName ?: string ; // populated if subquery
Original file line number Diff line number Diff line change @@ -867,12 +867,12 @@ export const testCases: TestCase[] = [
867867 fields : [
868868 {
869869 text : 'Name' ,
870- alias : 'c' ,
870+ objectPrefix : 'c' ,
871871 } ,
872872 {
873873 text : 'Account.Name' ,
874874 relationshipFields : [ 'Account' , 'Name' ] ,
875- alias : 'c' ,
875+ objectPrefix : 'c' ,
876876 } ,
877877 ] ,
878878 subqueries : [ ] ,
@@ -989,11 +989,11 @@ export const testCases: TestCase[] = [
989989 fields : [
990990 {
991991 text : 'Id' ,
992- alias : 'a' ,
992+ objectPrefix : 'a' ,
993993 } ,
994994 {
995995 text : 'Name' ,
996- alias : 'a' ,
996+ objectPrefix : 'a' ,
997997 } ,
998998 {
999999 subqueryObjName : 'ChildAccounts' ,
@@ -1007,7 +1007,7 @@ export const testCases: TestCase[] = [
10071007 fields : [
10081008 {
10091009 text : 'Id' ,
1010- alias : 'a2' ,
1010+ objectPrefix : 'a2' ,
10111011 } ,
10121012 ] ,
10131013 subqueries : [ ] ,
@@ -1018,7 +1018,7 @@ export const testCases: TestCase[] = [
10181018 fields : [
10191019 {
10201020 text : 'Id' ,
1021- alias : 'a1' ,
1021+ objectPrefix : 'a1' ,
10221022 } ,
10231023 ] ,
10241024 subqueries : [ ] ,
You can’t perform that action at this time.
0 commit comments