You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:sunny: This library allows parsing Salesforce SOQL queries using JavaScript or Typescript. Works in the browser and node. :sunny:
10
+
9
11
SOQL Parser JS provides the following capabilities:
10
12
11
13
1. Parse a SOQL query into a usable data structure.
12
-
2. Turn a parsed query data structure back into well a SOQL query with various format options.
13
-
3. Check if a SOQL query is syntactically valid (**note**: some cases may be structurally sound but not allowed by SFDC).
14
+
2. Turn a parsed data structure back into a well formed SOQL query with various format options.
15
+
3. Check if a SOQL query is syntactically valid (**note**: some cases may be structurally valid but not allowed by Salesforce, e.x. invalid field name).
14
16
15
17
This library is written in Typescript and all type definitions are included with the library for your benefit if you choose to use Typescript or use VSCode's automatic type checking.
16
18
17
-
_Warning_: antlr4 is dependency for this library and is a rather large library (~600 KB) and is required for the parser to function, use in the browser with care.
19
+
:warning: antlr4 is dependency for this library and is a rather large library (~600 KB) and is required for the parser to function. Consider using dynamic imports to achieve lazy loading.
18
20
19
21
## Examples
20
22
21
-
For an example of the parser, check out the [example application](https://paustint.github.io/soql-parser-js/).
23
+
Want to try it out? [Check out the demo](https://paustint.github.io/soql-parser-js/).
22
24
23
-
Have a look through the unit tests for many more examples.
25
+
Look through the [unit tests](./test/TestCases.ts) for additional examples.
24
26
25
27
# Usage
26
28
27
29
## Parsing
28
30
29
-
Parsing a SOQL query can be completed by calling `parseQuery(soqlQueryString, options)` and a`Query` data structure will be returned;
31
+
Parsing a SOQL query can be completed by calling `parseQuery(soqlQueryString, options)`. A`Query` data structure will be returned;
Composing a query will turn a Query object back to a SOQL query. The exact same data structure returned from `parseQuery()` can be used,
58
-
but there are many use-cases where you may need to build your own data structure to compose a query.
104
+
Composing a query will turn a Query object back to a SOQL query string. The exact same data structure returned from `parseQuery()` can be used,
105
+
but depending on your use-case, you may need to build your own data structure to compose a query.
59
106
These examples show building your own Query object with the minimum required fields.
60
107
61
-
**Note:**For some operators, they may be converted to upper case (e.x. NOT, AND)
108
+
:page_facing_up:**Note:**Some operators may be converted to upper case (e.x. NOT, AND)
62
109
63
-
**Note:** There are a number of fields populated on the Query object when `parseQuery()` is called that are not required to compose a query. Look at the examples below and the comments in the data model for more information.
110
+
:page_facing_up:**Note:** There are a number of fields populated on the Query object when `parseQuery()` is called that are not required to compose a query. Look at the examples below and the comments in the data model for more information.
64
111
65
112
**The base query object is shaped like this:**
66
113
@@ -84,7 +131,7 @@ The easiest way to build the fields is to call the utility function `getComposed
84
131
85
132
### Example
86
133
87
-
This is the query that will be composed
134
+
This is the query that will be composed programmatically
In the above examples, we made use of `getComposedField(input: string | ComposeFieldInput)` to help easily compose the fields. The input expects a string or one of the following shapes of data below. An error will be thrown if the data passed in is not one of the following shapes:
156
-
and will return a `FieldType` object.
202
+
In the example above, we made use of `getComposedField(input: string | ComposeFieldInput)` to compose the fields. The input expects a string or one of the following data structures listed below. An error will be thrown if the data passed in is not one of the following shapes.
1. Convenience method to construct fields in the correct data format. See example usage in the Compose example.
337
-
1.`isSubquery(query: Query | Subquery)`
338
-
1. Returns true if the data passed in is a subquery
339
-
1.`getFlattenedFields(query: Query)`
340
-
1. This provides a list of fields that are stringified and flattened in order to access data from a returned API call from Salesforce. Refer to `tests/publicUtils.spec.ts` for usage examples.
417
+
1. Convenience method to construct fields in the correct data format. See example usage in the Compose example.
418
+
2.`isSubquery(query: Query | Subquery)`
419
+
1. Returns true if the data passed in is a subquery
420
+
3.`getFlattenedFields(query: Query)`
421
+
1. Flatten a Salesforce record based on the parsed SOQL Query. this is useful if you have relationships in your query and want to show the results in a table, using `.` dot notation for the relationship fields.
422
+
2. Refer to `tests/publicUtils.spec.ts` for usage examples.
341
423
342
424
## Data Models
343
425
344
-
### Query
345
-
346
426
These are all available for import in your typescript projects
0 commit comments