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 avg/sum functions #22

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

Add support for avg/sum functions #22

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

As part of supporting aggregate functions add support for following functions:

AVG()
SUM()

Add avg and sum tag that can be used in selectClause structs as follows:

type TestSoqlStruct struct {
	SelectClause NestedStruct      `soql:"selectClause,tableName= Opportunity"`
	GroupBy        []string                 `soql:"groupByClause"`
}

type NestedStruct struct {
        CampaignId  string `soql:"selectColumn,fieldName= CampaignId"`
	Average         int `soql:"avg,fieldName= Amount"`
}

soqlStruct := TestSoqlStruct{
   GroupBy: []string{"CampaignId"},
}
soqlQuery, err := Marshal(soqlStruct)
if err != nil {
    fmt.Printf("Error in marshaling: %s\n", err.Error())
}
fmt.Println(soqlQuery)

This should result in SOQL as follows

SELECT CampaignId, AVG(Amount) FROM Opportunity GROUP BY CampaignId

Note that if fieldName is not specified then return ErrInvalidTag.

Same should apply for sum tag as well.

Allow avg and sum to be used only for supported primitive data types

@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