beyond-the-cloud-dev / soql-lib

The SOQL Lib provides functional constructs for SOQL queries in Apex.
https://soql.beyondthecloud.dev/
MIT License
63 stars 10 forks source link

Remove filter when logic expression evaluate to true #63

Closed pgajek2 closed 1 year ago

pgajek2 commented 1 year ago

Instead of doing this:

public SOQL.FilterGroup getFilters(String accountName, String accountIndustry) {
      SOQL.FilterGroup group = SOQL.FilterGroup;

      if (String.isNotBlank(accountName)) {
         group.add(SOQL.Filter.name().equal(accountName));
      }
      if (String.isNotBlank(accountIndustry)) {
         group.add(SOQL.Filter.with(Account.Industry).equal(accountIndustry));
      }

      return group;
}

Allow for something like that:

SOQL.FilterGroup
   .add(SOQL.Filter.name().equal(accountName).ignoreWhen(String.isBlank(accountName)))
   .add(SOQL.Filter.with(Account.Industry).equal(accountName).ignoreWhen(String.isBlank(accountIndustry)))