Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
pgajek2 committed May 31, 2023
1 parent 7357b19 commit 5d01b00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
31 changes: 12 additions & 19 deletions force-app/main/default/classes/SOQL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,14 @@ public inherited sharing class SOQL implements Queryable {
SOQL with(SObjectField field1, SObjectField field2, SObjectField field3);
SOQL with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4);
SOQL with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4, SObjectField field5);
SOQL with(Set<SObjectField> fields);
SOQL with(List<SObjectField> fields);

SOQL with(String fields);

SOQL with(List<SObjectField> fields); // For more than 5 fields
SOQL with(String fields); // Dynamic SOQL
SOQL with(String relationshipName, SObjectField field);
SOQL with(String relationshipName, SObjectField field1, SObjectField field2);
SOQL with(String relationshipName, SObjectField field1, SObjectField field2, SObjectField field3);
SOQL with(String relationshipName, SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4);
SOQL with(String relationshipName, SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4, SObjectField field5);
SOQL with(String relationshipName, List<SObjectField> fields);

SOQL with(String relationshipName, List<SObjectField> fields); // For more than 5 fields
SOQL with(SubQuery subQuery); // SOQL.SubQuery

SOQL count();
Expand All @@ -77,7 +73,7 @@ public inherited sharing class SOQL implements Queryable {
SOQL teamScope();

SOQL whereAre(FilterClause conditions); // SOQL.FilterGroup or SOQL.Filter
SOQL whereAre(String conditions); // conditions to evaluate
SOQL whereAre(String conditions); // Conditions to evaluate

SOQL groupBy(SObjectField field);
SOQL groupByRollup(SObjectField field);
Expand Down Expand Up @@ -134,7 +130,7 @@ public inherited sharing class SOQL implements Queryable {
SubQuery with(SObjectField field1, SObjectField field2, SObjectField field3);
SubQuery with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4);
SubQuery with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4, SObjectField field5);
SubQuery with(List<SObjectField> fields);
SubQuery with(List<SObjectField> fields); // For more than 5 fields
SubQuery with(String relationshipName, List<SObjectField> fields);

SubQuery whereAre(FilterClause conditions); // SOQL.FilterGroup or SOQL.Filter
Expand Down Expand Up @@ -177,18 +173,19 @@ public inherited sharing class SOQL implements Queryable {
Filter startsWith(String value); // LIKE :value + '%'
Filter isIn(Set<String> inSet); // IN :inSet
Filter isIn(List<Object> inList); // IN :inList
Filter isIn(JoinQuery joinQuery); // SOQL.JoinQuery
Filter notIn(Set<String> inSet); // NOT IN :inSet
Filter notIn(List<Object> inList); // NOT IN :inList

Filter isIn(JoinQuery joinQuery); // SOQL.JoinQuery
Filter notIn(JoinQuery joinQuery); // SOQL.JoinQuery

Filter removeWhenNull();
Filter removeWhenNull(); // Condition will be removed for value = null
}

public interface SoqlFiltersGroup { // SOQL.FilterGroup
FilterGroup add(FilterClause condition); // SOQL.Filter or SOQL.FilterGroup
FilterGroup anyConditionMatching(); // Join with OR

FilterGroup anyConditionMatching(); // All group filters will be join by OR

FilterGroup conditionLogic(String order);
}

Expand Down Expand Up @@ -220,6 +217,8 @@ public inherited sharing class SOQL implements Queryable {
mock.setStaticResourceMock(mockId, staticResource);
}

// Config

private static Mock mock = new Mock();

private QueryBuilder builder;
Expand Down Expand Up @@ -257,10 +256,6 @@ public inherited sharing class SOQL implements Queryable {
return with(field1).with(field2).with(field3).with(field4).with(field5);
}

public SOQL with(Set<SObjectField> fields) {
return with(new List<SObjectField>(fields));
}

public SOQL with(List<SObjectField> fields) {
builder.fields.with(fields);
return this;
Expand Down Expand Up @@ -517,8 +512,6 @@ public inherited sharing class SOQL implements Queryable {
return whereAre(Filter.id().isIn(records));
}

// Config

public interface QueryClause {
String build();
}
Expand Down
12 changes: 0 additions & 12 deletions force-app/main/default/classes/SOQL_Test.cls
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,6 @@ private class SOQL_Test {
Assert.areEqual('SELECT Id, Name, BillingCity, AccountNumber, AccountSource FROM Account', soql);
}

@IsTest
static void withSetOfFields() {
// Test
String soql = SOQL.of(Account.SObjectType)
.with(new Set<SObjectField>{
Account.Name, Account.BillingCity
}).toString();

// Verify
Assert.areEqual('SELECT Name, BillingCity FROM Account', soql);
}

@IsTest
static void withListOfFields() {
// Test
Expand Down

1 comment on commit 5d01b00

@vercel
Copy link

@vercel vercel bot commented on 5d01b00 May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.