-
Notifications
You must be signed in to change notification settings - Fork 6
model WHERE clause #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #68 +/- ##
===========================================
+ Coverage 94.12% 94.14% +0.02%
===========================================
Files 33 42 +9
Lines 851 1076 +225
Branches 177 227 +50
===========================================
+ Hits 801 1013 +212
- Misses 48 61 +13
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
| new model.Impl.WhereImpl( | ||
| new model.Impl.FieldCompareConditionImpl( | ||
| new model.Impl.FieldRefImpl('field1'), | ||
| model.Soql.CompareOperator.EQ, | ||
| new model.Impl.LiteralImpl(model.Soql.LiteralType.Number, '5') | ||
| ) | ||
| ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sample script update
| var where = queryModel.where ? queryModel.where.toSoqlSyntax() : undefined; | ||
| var orderBy = queryModel.orderBy.orderByExpressions.map( | ||
| (expr) => `${expr.field.fieldName} ${expr.order} ${expr.nullsOrder}` | ||
| ); | ||
| var limit = queryModel.limit ? queryModel.limit.limit : 'undefined'; | ||
| console.log(`Query: ${query}`); | ||
| console.log(`SObject: ${sObject}`); | ||
| console.log(`Fields: ${fields}`); | ||
| console.log(`Where: ${where}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sample script update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would line 32 be good to look at to get an idea of whats available to the UI for a where clause?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No that's just the where clause transformed back to SOQL syntax. Line 16 of getquery.js is indicative of how the model is created. For raw JSON, deserializer.test.ts has lots of examples of what these different conditions look like when modeled in a WHERE clause.
| protected isIncompleteLimitError(error: ParserError): boolean { | ||
| const context = this.matchErrorToContext(error); | ||
| return context instanceof Parser.SoqlIntegerContext | ||
| return context instanceof Parser.SoqlIntegerValueContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is due to a parser rule rename in the new soql parser version
| protected toLiteral(ctx: ParserRuleContext): Soql.Literal { | ||
| if (ctx instanceof Parser.SoqlLiteralLiteralValueContext) { | ||
| ctx = ctx.soqlLiteral(); | ||
| } | ||
| if (ctx instanceof Parser.SoqlLiteralCommonLiteralsContext) { | ||
| ctx = ctx.soqlCommonLiterals(); | ||
| } | ||
| if (ctx instanceof Parser.SoqlDateLiteralContext) { | ||
| return new Impl.LiteralImpl(Soql.LiteralType.Date, ctx.getText()); | ||
| } else if (ctx instanceof Parser.SoqlDateTimeLiteralContext) { | ||
| return new Impl.LiteralImpl(Soql.LiteralType.Date, ctx.getText()); | ||
| } else if (ctx instanceof Parser.SoqlTimeLiteralContext) { | ||
| return new Impl.LiteralImpl(Soql.LiteralType.Date, ctx.getText()); | ||
| } else if (ctx instanceof Parser.SoqlDateFormulaLiteralContext) { | ||
| return new Impl.LiteralImpl(Soql.LiteralType.Date, ctx.getText()); | ||
| } else if (ctx instanceof Parser.SoqlNumberLiteralContext) { | ||
| return new Impl.LiteralImpl(Soql.LiteralType.Number, ctx.getText()); | ||
| } else if (ctx instanceof Parser.SoqlNullLiteralContext) { | ||
| return new Impl.LiteralImpl(Soql.LiteralType.Null, ctx.getText()); | ||
| } else if (ctx instanceof Parser.SoqlBooleanLiteralContext) { | ||
| return new Impl.LiteralImpl(Soql.LiteralType.Boolean, ctx.getText()); | ||
| } else if (ctx instanceof Parser.SoqlMultiCurrencyContext) { | ||
| return new Impl.LiteralImpl(Soql.LiteralType.Currency, ctx.getText()); | ||
| } | ||
| return new Impl.LiteralImpl(Soql.LiteralType.String, ctx.getText()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Literals are stored as a type (date, number, null, boolean, currency, string) and a value. The value is the string value of the token. So a literal of type string has a value that includes the quotes. Storing the literal values this way, as opposed to storing as a Javascript version of the type, avoids any messy type transformations.
|
The latest commit |
|
The commit |
|
Looks good to me 👍 For future PRs: Given that model is growing, Have you thought of providing "builders" to make it easier to build model structures? (for unit tests and for the UI editor). Something like: |
* model WHERE clause (#68) * Remote SOQL Errors - Language Server Part (#93) * remove code builder (#92) * Move from antlr4JS to antlr4TS (#96) * SOQL code completion for SELECT fields (#99) * publish language server 0.2.9 (#102) * Fix LSP dependency (#104) * Disabled 'Running...' button while query running (#106) * Add basic code-completion for ORDER BY and other improvements (#107) * Dehru and JG telemetry - Send GDPR clean data to telemetry when errors/unsupported syntax present (#110) * Disable WHERE in model (#113) * Bump versions for publishing (#114) * Code-completion for WHERE clause expressions (#112) Co-authored-by: Jonathan Gellin <jgellin@salesforce.com> Co-authored-by: jgellin-sf <55159130+jgellin-sf@users.noreply.github.com> Co-authored-by: Chase McCarthy <charles.mccarthy@heroku.com> Co-authored-by: Jonny Hork <jhork@salesforce.com> Co-authored-by: Fernando Dobladez <fernandodobladez@salesforce.com> Co-authored-by: Jonathan Gellin <jgellin@salesforce.com>
What does this PR do?
This PR models the WHERE clause. All types of conditions are modeled except for the following, which are modeled as
UnmodeledSyntax:field IN (SELECT A FROM B)DISTANCE(field,GEOLOCATION(37,122),'mi') < 100A + B > 10field = :varThis PR also updates the soql parser to version 0.17. This update includes better handling of WHERE expressions (timely!) and several other updates. Some rules were renamed, resulting in some minor code changes in this PR.
What issues does this PR fix or reference?
W-8295457