-
Notifications
You must be signed in to change notification settings - Fork 8
Added support for database access levels and new query methods with binds #49
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
Changes from 4 commits
00d196d
82c6d68
100d090
f183a76
158db75
f497090
9a3f1c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,7 @@ global class AggregateQuery extends SOQL { | |||||||||
| private SOQL.GroupingDimension groupingDimension; | ||||||||||
| private List<AggregateField> aggregateFields; | ||||||||||
| private List<String> havingConditions; | ||||||||||
| private String countQuery; | ||||||||||
|
|
||||||||||
| global AggregateQuery(Schema.SObjectType sobjectType) { | ||||||||||
| super(sobjectType, false); | ||||||||||
|
|
@@ -79,19 +80,48 @@ global class AggregateQuery extends SOQL { | |||||||||
| return this.havingAggregate(aggregateFunction, new SOQL.QueryField(field), operator, value); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| global AggregateQuery havingAggregate(SOQL.Aggregate aggregateFunction, Schema.SObjectField field, SOQL.Operator operator, Object value, String bindWithKey) { | ||||||||||
| return this.havingAggregate(aggregateFunction, new SOQL.QueryField(field), operator, value, bindWithKey); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| global AggregateQuery havingAggregate(SOQL.Aggregate aggregateFunction, SOQL.QueryField queryField, SOQL.Operator operator, Object value) { | ||||||||||
| this.havingConditions.add(aggregateFunction.name() + '(' + queryField + ') ' + SOQL.getOperatorValue(operator) + ' ' + value); | ||||||||||
| return this.havingAggregate(aggregateFunction, queryField, operator, value, null); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| global AggregateQuery havingAggregate(SOQL.Aggregate aggregateFunction, SOQL.QueryField queryField, SOQL.Operator operator, Object value, String bindWithKey) { | ||||||||||
| this.havingConditions.add( | ||||||||||
| String.format( | ||||||||||
| '{0}({1}) {2} {3}', | ||||||||||
| new List<String> { | ||||||||||
| aggregateFunction.name(), | ||||||||||
| queryField.toString(), | ||||||||||
| SOQL.getOperatorValue(operator), | ||||||||||
| (String.isNotBlank(bindWithKey) ? ':' + bindWithKey : new QueryArgument(value).toString()) | ||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love how you've kept it backwards compatible with |
||||||||||
| } | ||||||||||
| ) | ||||||||||
| ); | ||||||||||
| if (String.isNotBlank(bindWithKey)) { | ||||||||||
| this.bindsMap.put(bindWithKey, value); | ||||||||||
| } | ||||||||||
| return this.setHasChanged(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| global AggregateQuery filterWhere(Schema.SObjectField field, SOQL.Operator operator, Object value) { | ||||||||||
| return this.filterWhere(new SOQL.QueryField(field), operator, value); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| global AggregateQuery filterWhere(Schema.SObjectField field, SOQL.Operator operator, Object value, String bindWithKey) { | ||||||||||
| return this.filterWhere(new SOQL.QueryField(field), operator, value, bindWithKey); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| global AggregateQuery filterWhere(SOQL.QueryField queryField, SOQL.Operator operator, Object value) { | ||||||||||
| return this.filterWhere(new SOQL.QueryFilter(queryField, operator, value)); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| global AggregateQuery filterWhere(SOQL.QueryField queryField, SOQL.Operator operator, Object value, String bindWithKey) { | ||||||||||
| return this.filterWhere(new SOQL.QueryFilter(queryField, operator, value, bindWithKey)); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| global AggregateQuery filterWhere(SOQL.QueryFilter filter) { | ||||||||||
| return this.filterWhere(new List<SOQL.QueryFilter>{ filter }); | ||||||||||
| } | ||||||||||
|
|
@@ -106,6 +136,11 @@ global class AggregateQuery extends SOQL { | |||||||||
| return this.setHasChanged(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| global AggregateQuery withAccessLevel(System.AccessLevel mode) { | ||||||||||
| super.doWithAccessLevel(mode); | ||||||||||
|
||||||||||
| global AggregateQuery withAccessLevel(System.AccessLevel mode) { | |
| super.doWithAccessLevel(mode); | |
| global AggregateQuery withAccessLevel(System.AccessLevel accessLevel) { | |
| super.doWithAccessLevel(accessLevel); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <apiVersion>58.0</apiVersion> | ||
| <apiVersion>60.0</apiVersion> | ||
|
||
| <status>Active</status> | ||
| </ApexClass> | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -199,10 +199,18 @@ global class Query extends SOQL { | |||||||||
| return this.filterWhere(new SOQL.QueryField(field), operator, value); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| global Query filterWhere(Schema.SObjectField field, SOQL.Operator operator, Object value, String bindWithKey) { | ||||||||||
| return this.filterWhere(new SOQL.QueryField(field), operator, value, bindWithKey); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| global Query filterWhere(SOQL.QueryField queryField, SOQL.Operator operator, Object value) { | ||||||||||
| return this.filterWhere(new SOQL.QueryFilter(queryField, operator, value)); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| global Query filterWhere(SOQL.QueryField queryField, SOQL.Operator operator, Object value, String bindWithKey) { | ||||||||||
| return this.filterWhere(new SOQL.QueryFilter(queryField, operator, value, bindWithKey)); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| global Query filterWhere(SOQL.QueryFilter filter) { | ||||||||||
| return this.filterWhere(new List<SOQL.QueryFilter>{ filter }); | ||||||||||
| } | ||||||||||
|
|
@@ -239,6 +247,11 @@ global class Query extends SOQL { | |||||||||
| //return this.setHasChanged(); | ||||||||||
| //} | ||||||||||
|
|
||||||||||
| global Query withAccessLevel(System.AccessLevel mode) { | ||||||||||
| super.doWithAccessLevel(mode); | ||||||||||
|
||||||||||
| global Query withAccessLevel(System.AccessLevel mode) { | |
| super.doWithAccessLevel(mode); | |
| global Query withAccessLevel(System.AccessLevel accessLevel) { | |
| super.doWithAccessLevel(accessLevel); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <apiVersion>58.0</apiVersion> | ||
| <apiVersion>60.0</apiVersion> | ||
| <status>Active</status> | ||
| </ApexClass> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -64,6 +64,11 @@ global class RecordSearch extends SOSL { | |||||
| return this.setHasChanged(); | ||||||
| } | ||||||
|
|
||||||
| global RecordSearch withAccessLevel(System.AccessLevel accessLevel) { | ||||||
| this.accessLevel = accessLevel; | ||||||
|
||||||
| this.accessLevel = accessLevel; | |
| super.doWithAccessLevel(accessLevel); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <apiVersion>58.0</apiVersion> | ||
| <apiVersion>60.0</apiVersion> | ||
| <status>Active</status> | ||
| </ApexClass> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <apiVersion>58.0</apiVersion> | ||
| <apiVersion>60.0</apiVersion> | ||
| <status>Active</status> | ||
| </ApexClass> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this new method overload signature makes sense, especially for trying to keep things backwards compatible with
QueryArgument. But my small complaint is:QueryArgumentSo I'm thinking there could be another method to enable automatically generating bind variable names. Something like this:
And then in this
havingAggregate()overload, auto-generate the bind var name when enabled:Example usage would look something like this:
I think the same idea would apply in the
Queryclass too. Let me know what you think.