forcedotcom / go-soql

Golang tag library to generate SOQL queries
BSD 3-Clause "New" or "Revised" License
52 stars 12 forks source link

Add support for limit and offset clause #4

Closed atulkc closed 4 years ago

atulkc commented 4 years ago

Add support to tag int member with limitClause and offsetClause and include it in generated SOQL query. Here is how it should work:

type TestSoqlStruct struct {
    SelectClause NonNestedStruct   `soql:"selectClause,tableName=SM_SomeObject__c"`
    WhereClause  TestQueryCriteria `soql:"whereClause"`
    Limit        int               `soql:"limitClause"`
    Offset       int               `soql:"offsetClause"`
}
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"`
}

o use above structs to create SOQL query

soqlStruct := TestSoqlStruct{
    WhereClause: TestQueryCriteria {
        IncludeNamePattern: []string{"foo", "bar"},
        Roles: []string{"admin", "user"},
    }
    Limit: 10,
    Offset: 5,
}
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') LIMIT 10 OFFSET 5
atulkc commented 4 years ago

Closed by https://github.com/forcedotcom/go-soql/pull/10