Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for groupBy clause #19

Open
atulkc opened this issue Aug 18, 2020 · 0 comments
Open

Add support for groupBy clause #19

atulkc opened this issue Aug 18, 2020 · 0 comments
Labels
aggregate-functions help wanted Extra attention is needed

Comments

@atulkc
Copy link
Collaborator

atulkc commented Aug 18, 2020

Library should support GROUP BY clause. User should be able to annotate []string member of struct with groupBy tag. The values in the []string should be the names of the field of the struct that is tagged as selectClause. This will enable developers to take []string as parameter to their method where the users of their library can specify the name of the fields of the struct that is being returned to them on which they desire grouping. Below given is example of how this should work:

type TestSoqlStruct struct {
	SelectClause NonNestedStruct   `soql:"selectClause,tableName=SM_SomeObject__c"`
	WhereClause  TestQueryCriteria `soql:"whereClause"`
	GroupBy   []string                         `soql:"groupByClause"`
}
type TestQueryCriteria struct {
	IncludeNamePattern          []string `soql:"likeOperator,fieldName=Name__c"`
	Roles                                   []string `soql:"inOperator,fieldName=Role__c"`
}
type NonNestedStruct struct {
	Name              string `soql:"selectColumn,fieldName=Name__c"`
	SomeValue     string `soql:"selectColumn,fieldName=SomeValue__c"`
}

To use above structs to create SOQL query

soqlStruct := TestSoqlStruct{
    WhereClause: TestQueryCriteria {
        IncludeNamePattern: []string{"foo", "bar"},
        Roles: []string{"admin", "user"},
    },
   GroupBy: []string{"SomeValue"},
}
soqlQuery, err := Marshal(soqlStruct)
if err != nil {
    fmt.Printf("Error in marshaling: %s\n", err.Error())
}
fmt.Println(soqlQuery)

Above struct will result in following SOQL query:

SELECT Name,SomeValue__c FROM SM_SomeObject__C WHERE (Name__c LIKE '%foo%' OR Name__c LIKE '%bar%') AND Role__c IN ('admin','user') GROUP BY SomeValue___c 
@atulkc atulkc added the help wanted Extra attention is needed label Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aggregate-functions help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant