jetstreamapp / soql-parser-js

Javascript SOQL parser
https://jetstreamapp.github.io/soql-parser-js/
MIT License
77 stars 20 forks source link

Make `Compose.parseWhereClause(where)` a public method #65

Closed justinleebehnke closed 5 years ago

justinleebehnke commented 5 years ago
paustint commented 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%')`);
  });