4an70m / apex-query-builder Goto Github PK
View Code? Open in Web Editor NEWConvenient query builder for dynamic SOQL queries
License: MIT License
Convenient query builder for dynamic SOQL queries
License: MIT License
The following query works as expected:
new QueryBuilder(Account.class)
.addField(Account.Name)
.addConditions()
.add(new QueryBuilder.SimpleCondition('Name = \'acc1\''))
.add(new QueryBuilder.SimpleCondition('Name = \'acc2\''))
.add(new QueryBuilder.SimpleCondition('Name = \'acc3\''))
.add(new QueryBuilder.SimpleCondition('Name = \'acc4\''))
(...)
.add(new QueryBuilder.SimpleCondition('Name = \'acc12\''))
.setConditionOrder('1 OR 2 OR 12')
.preview();
Name = 'acc1' OR Name = 'acc2' OR Name = 'acc12'
, but if we change the order:
.setConditionOrder('12 OR 1 OR 2')
, the query gets malformed:
Name = 'acc1'Name = 'acc2' OR 1 OR 2
, since 12
is replaced by {1}{2}
in bracketConditions
(and the subsequent 1
and 2
are left unbracketed ).
create a simple query select id, name from account
add a sub query to an object which also has Name as a field
( Id, Name from xxx__r )
expect both sobjects to have name field returned
observed the Name field is removed from the subquery
testClone1()
testToString()
Personally, I wouldn't try to format (prettify) the query string because that will introduce a bunch of problems when trying to test the final query string.
The operators INCLUDES and EXCLUDES, essential for the mutipicklists, are not currently supported by this framework. Please add them, preferably as extends FieldCondition
.
Currently no datetime is supported.
Something like this would be appreciated.
Also date literals would be great.
private static final String GMT_DATE_FORMAT = 'yyyy-MM-dd\'T\'HH:mm:ss\'Z\'';
public class CompareCondition extends FieldCondition {
....
public Condition lt(Datetime fieldValue) {
this.formedCondition = this.fieldName + ' < ' + fieldValue.formatGmt(GMT_DATE_FORMAT);
return this;
}
public Condition gt(Datetime fieldValue) {
this.formedCondition = this.fieldName + ' > ' + fieldValue.formatGmt(GMT_DATE_FORMAT);
return this;
}
public Condition lte(Datetime fieldValue) {
this.formedCondition = this.fieldName + ' <= ' + fieldValue.formatGmt(GMT_DATE_FORMAT);
return this;
}
public Condition gte(Datetime fieldValue) {
this.formedCondition = this.fieldName + ' >= ' + fieldValue.formatGmt(GMT_DATE_FORMAT);
return this;
}
}
Current behaviour:
new QueryBuilder(Account.class)
.addConditions()
.add(new QueryBuilder.SimpleCondition('Name = \'Test\'')
.add(new QueryBuilder.SimpleCondition('Field2 = \'Test\'')
.endConditions()
.toString();
// returns SELECT Id FROM Account WHERE Name = 'Test'
Expected behaviour:
SELECT Id FROM Account WHERE Name = 'Test' AND Field2 = 'Test'
If there is no explicit ordering set I think it should implicitly join all Conditions with an AND
clause
I have it implemented -> should I send PR?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.