Closed justinleebehnke closed 5 years ago
@justinleebehnke - This makes sense to me and I think that it should be available. I am working on it now and writing some tests to make sure I did not break anything as well as updating the README with examples.
You will need to create a new instance of the Compose
class and pass in a new option { autoCompose: false }
- this ensures that the passed in query data will not be autocomposed into a soql query string - since for your use-case you will only need to compose one part of the parsed query.
I should have a new version published today.
Here is an example of how it will be used:
it(`Should compose the where clause properly`, () => {
const soql = `SELECT Id FROM Account WHERE Name = 'Foo'`;
const parsedQuery = parseQuery(soql);
const composer = new Compose(parsedQuery, { autoCompose: false });
const whereClause = composer.parseWhereClause(parsedQuery.where);
expect(whereClause).to.equal(`Name = 'Foo'`);
});
it(`Should compose the where clause properly with semi-join`, () => {
const soql = `SELECT Id FROM Account WHERE Id IN (SELECT AccountId FROM Contact WHERE Name LIKE '%foo%')`;
const parsedQuery = parseQuery(soql);
const composer = new Compose(parsedQuery, { autoCompose: false });
const whereClause = composer.parseWhereClause(parsedQuery.where);
expect(whereClause).to.equal(`Id IN (SELECT AccountId FROM Contact WHERE Name LIKE '%foo%')`);
});
Description
I might be a random edge case but for me personally, I need the WHERE clause as a string. I know I could traverse the awesome tree structure that you have built in for the WHERE clause, it really is awesome, but I am 99% sure that's exactly what's going on in the
parseWhereClause()
method. Just a thought. I really appreciate your repo it's very nice.