-
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d3d784c
model WHERE clause
jgellin-sf 4e32d91
make IN and INCLUDES conditions unmodeled syntax
jgellin-sf 18e19f3
implement condition simplicity utils
jgellin-sf 63f5713
added where complexity to script statement
8bd8fb3
Merge branch 'jg/where' of https://github.com/forcedotcom/soql-toolin…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/soql-model/src/model/impl/andOrConditionImpl.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright (c) 2020, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import * as Impl from '.'; | ||
| import { AndOr, CompareOperator, LiteralType } from '../model'; | ||
|
|
||
| describe('AndOrConditionImpl should', () => { | ||
| it('store left and right conditions and the AndOr operator', () => { | ||
| const expected = { | ||
| leftCondition: { field: { fieldName: 'field' }, operator: '>', compareValue: { type: 'NUMBER', value: '1' } }, | ||
| andOr: 'OR', | ||
| rightCondition: { field: { fieldName: 'field' }, operator: '<', compareValue: { type: 'NUMBER', value: '5' } } | ||
| }; | ||
| const actual = new Impl.AndOrConditionImpl( | ||
| new Impl.FieldCompareConditionImpl(new Impl.FieldRefImpl('field'), CompareOperator.GT, new Impl.LiteralImpl(LiteralType.Number, '1')), | ||
| AndOr.Or, | ||
| new Impl.FieldCompareConditionImpl(new Impl.FieldRefImpl('field'), CompareOperator.LT, new Impl.LiteralImpl(LiteralType.Number, '5')) | ||
| ); | ||
| expect(actual).toEqual(expected); | ||
| }); | ||
| it('return left condition followed by AndOr operator followed by right condition for toSoqlSyntax()', () => { | ||
| const expected = 'field > 1 OR field < 5'; | ||
| const actual = new Impl.AndOrConditionImpl( | ||
| new Impl.FieldCompareConditionImpl(new Impl.FieldRefImpl('field'), CompareOperator.GT, new Impl.LiteralImpl(LiteralType.Number, '1')), | ||
| AndOr.Or, | ||
| new Impl.FieldCompareConditionImpl(new Impl.FieldRefImpl('field'), CompareOperator.LT, new Impl.LiteralImpl(LiteralType.Number, '5')) | ||
| ).toSoqlSyntax(); | ||
| expect(actual).toEqual(expected); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * Copyright (c) 2020, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import * as Soql from '../model'; | ||
| import { SoqlModelObjectImpl } from './soqlModelObjectImpl'; | ||
|
|
||
| export class AndOrConditionImpl extends SoqlModelObjectImpl implements Soql.AndOrCondition { | ||
| public constructor(public leftCondition: Soql.Condition, public andOr: Soql.AndOr, public rightCondition: Soql.Condition) { | ||
| super(); | ||
| } | ||
| public toSoqlSyntax(options?: Soql.SyntaxOptions): string { | ||
| return `${this.leftCondition.toSoqlSyntax(options)} ${this.andOr} ${this.rightCondition.toSoqlSyntax(options)}`; | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
packages/soql-model/src/model/impl/fieldCompareConditionImpl.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright (c) 2020, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import * as Impl from '.'; | ||
| import { CompareOperator, LiteralType } from '../model'; | ||
|
|
||
| describe('FieldCompareConditionImpl should', () => { | ||
| it('store field, operator, and value', () => { | ||
| const expected = { field: { fieldName: 'field' }, operator: '=', compareValue: { type: 'STRING', value: "'abc'" } }; | ||
| const actual = new Impl.FieldCompareConditionImpl( | ||
| new Impl.FieldRefImpl('field'), | ||
| CompareOperator.EQ, | ||
| new Impl.LiteralImpl(LiteralType.String, "'abc'") | ||
| ); | ||
| expect(actual).toEqual(expected); | ||
| }); | ||
| it('return field, operator, and value separated by spaces for toSoqlSyntax()', () => { | ||
| const expected = `field = 'abc'`; | ||
| const actual = new Impl.FieldCompareConditionImpl( | ||
| new Impl.FieldRefImpl('field'), | ||
| CompareOperator.EQ, | ||
| new Impl.LiteralImpl(LiteralType.String, "'abc'") | ||
| ).toSoqlSyntax(); | ||
| expect(actual).toEqual(expected); | ||
| }); | ||
| }); |
18 changes: 18 additions & 0 deletions
18
packages/soql-model/src/model/impl/fieldCompareConditionImpl.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * Copyright (c) 2020, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import * as Soql from '../model'; | ||
| import { SoqlModelObjectImpl } from './soqlModelObjectImpl'; | ||
|
|
||
| export class FieldCompareConditionImpl extends SoqlModelObjectImpl implements Soql.FieldCompareCondition { | ||
| public constructor(public field: Soql.Field, public operator: Soql.CompareOperator, public compareValue: Soql.CompareValue) { | ||
| super(); | ||
| } | ||
| public toSoqlSyntax(options?: Soql.SyntaxOptions): string { | ||
| return `${this.field.toSoqlSyntax(options)} ${this.operator} ${this.compareValue.toSoqlSyntax(options)}`; | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
packages/soql-model/src/model/impl/inListConditionImpl.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright (c) 2020, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import * as Impl from '.'; | ||
| import { InOperator, LiteralType } from '../model'; | ||
|
|
||
| describe('InListConditionImpl should', () => { | ||
| it('store field, operator, and values', () => { | ||
| const expected = { field: { fieldName: 'field' }, operator: 'NOT IN', values: [{ type: 'STRING', value: "'abc'" }, { type: 'STRING', value: "'def'" }] }; | ||
| const actual = new Impl.InListConditionImpl( | ||
| new Impl.FieldRefImpl('field'), | ||
| InOperator.NotIn, | ||
| [new Impl.LiteralImpl(LiteralType.String, "'abc'"), new Impl.LiteralImpl(LiteralType.String, "'def'")] | ||
| ); | ||
| expect(actual).toEqual(expected); | ||
| }); | ||
| it('return field, operator, and parenthesized comma-separated values separated by spaces for toSoqlSyntax()', () => { | ||
| const expected = "field NOT IN ( 'abc', 'def' )"; | ||
| const actual = new Impl.InListConditionImpl( | ||
| new Impl.FieldRefImpl('field'), | ||
| InOperator.NotIn, | ||
| [new Impl.LiteralImpl(LiteralType.String, "'abc'"), new Impl.LiteralImpl(LiteralType.String, "'def'")] | ||
| ).toSoqlSyntax(); | ||
| expect(actual).toEqual(expected); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * Copyright (c) 2020, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import * as Soql from '../model'; | ||
| import { SoqlModelObjectImpl } from './soqlModelObjectImpl'; | ||
|
|
||
| export class InListConditionImpl extends SoqlModelObjectImpl implements Soql.InListCondition { | ||
| public constructor(public field: Soql.Field, public operator: Soql.InOperator, public values: Soql.CompareValue[]) { | ||
| super(); | ||
| } | ||
| public toSoqlSyntax(options?: Soql.SyntaxOptions): string { | ||
| let valuesSyntax = ''; | ||
| this.values.forEach(value => valuesSyntax = `${valuesSyntax}, ${value.toSoqlSyntax(options)}`); | ||
| if (valuesSyntax.length > 2) { | ||
| // remove comma separator at start of string | ||
| valuesSyntax = valuesSyntax.substring(2); | ||
| } | ||
| return `${this.field.toSoqlSyntax(options)} ${this.operator} ( ${valuesSyntax} )`; | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
packages/soql-model/src/model/impl/includesConditionImpl.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright (c) 2020, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import * as Impl from '.'; | ||
| import { IncludesOperator, LiteralType } from '../model'; | ||
|
|
||
| describe('IncludesConditionImpl should', () => { | ||
| it('store field, operator, and values', () => { | ||
| const expected = { field: { fieldName: 'field' }, operator: 'INCLUDES', values: [{ type: 'STRING', value: "'abc'" }, { type: 'STRING', value: "'def'" }] }; | ||
| const actual = new Impl.IncludesConditionImpl( | ||
| new Impl.FieldRefImpl('field'), | ||
| IncludesOperator.Includes, | ||
| [new Impl.LiteralImpl(LiteralType.String, "'abc'"), new Impl.LiteralImpl(LiteralType.String, "'def'")] | ||
| ); | ||
| expect(actual).toEqual(expected); | ||
| }); | ||
| it('return field, operator, and parenthesized comma-separated values separated by spaces for toSoqlSyntax()', () => { | ||
| const expected = "field INCLUDES ( 'abc', 'def' )"; | ||
| const actual = new Impl.IncludesConditionImpl( | ||
| new Impl.FieldRefImpl('field'), | ||
| IncludesOperator.Includes, | ||
| [new Impl.LiteralImpl(LiteralType.String, "'abc'"), new Impl.LiteralImpl(LiteralType.String, "'def'")] | ||
| ).toSoqlSyntax(); | ||
| expect(actual).toEqual(expected); | ||
| }); | ||
| }); |
24 changes: 24 additions & 0 deletions
24
packages/soql-model/src/model/impl/includesConditionImpl.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * Copyright (c) 2020, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import * as Soql from '../model'; | ||
| import { SoqlModelObjectImpl } from './soqlModelObjectImpl'; | ||
|
|
||
| export class IncludesConditionImpl extends SoqlModelObjectImpl implements Soql.IncludesCondition { | ||
| public constructor(public field: Soql.Field, public operator: Soql.IncludesOperator, public values: Soql.CompareValue[]) { | ||
| super(); | ||
| } | ||
| public toSoqlSyntax(options?: Soql.SyntaxOptions): string { | ||
| let valuesSyntax = ''; | ||
| this.values.forEach(value => valuesSyntax = `${valuesSyntax}, ${value.toSoqlSyntax(options)}`); | ||
| if (valuesSyntax.length > 2) { | ||
| // remove comma separator at start of string | ||
| valuesSyntax = valuesSyntax.substring(2); | ||
| } | ||
| return `${this.field.toSoqlSyntax(options)} ${this.operator} ( ${valuesSyntax} )`; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,39 @@ | ||
| import { AndOrConditionImpl } from './andOrConditionImpl'; | ||
| import { FieldCompareConditionImpl } from './fieldCompareConditionImpl'; | ||
| import { FieldRefImpl } from './fieldRefImpl'; | ||
| import { FieldSelectionImpl } from './fieldSelectionImpl'; | ||
| import { FromImpl } from './fromImpl'; | ||
| import { IncludesConditionImpl } from './includesConditionImpl'; | ||
| import { InListConditionImpl } from './inListConditionImpl'; | ||
| import { LikeConditionImpl } from './likeConditionImpl'; | ||
| import { LimitImpl } from './limitImpl'; | ||
| import { LiteralImpl } from './literalImpl'; | ||
| import { NestedConditionImpl } from './nestedConditionImpl'; | ||
| import { NotConditionImpl } from './notConditionImpl'; | ||
| import { OrderByImpl } from './orderByImpl'; | ||
| import { OrderByExpressionImpl } from './orderByExpressionImpl'; | ||
| import { QueryImpl } from './queryImpl'; | ||
| import { SelectExprsImpl } from './selectExprsImpl'; | ||
| import { WhereImpl } from './whereImpl'; | ||
| import { UnmodeledSyntaxImpl } from './unmodeledSyntaxImpl'; | ||
|
|
||
| export { | ||
| AndOrConditionImpl, | ||
| FieldCompareConditionImpl, | ||
| FieldRefImpl, | ||
| FieldSelectionImpl, | ||
| FromImpl, | ||
| IncludesConditionImpl, | ||
| InListConditionImpl, | ||
| LikeConditionImpl, | ||
| LimitImpl, | ||
| LiteralImpl, | ||
| NestedConditionImpl, | ||
| NotConditionImpl, | ||
| QueryImpl, | ||
| SelectExprsImpl, | ||
| OrderByImpl, | ||
| OrderByExpressionImpl, | ||
| WhereImpl, | ||
| UnmodeledSyntaxImpl, | ||
| }; |
28 changes: 28 additions & 0 deletions
28
packages/soql-model/src/model/impl/likeConditionImpl.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright (c) 2020, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import * as Impl from '.'; | ||
| import { LiteralType } from '../model'; | ||
|
|
||
| describe('LikeConditionImpl should', () => { | ||
| it('store field and value', () => { | ||
| const expected = { field: { fieldName: 'field' }, compareValue: { type: 'STRING', value: "'abc'" } }; | ||
| const actual = new Impl.LikeConditionImpl( | ||
| new Impl.FieldRefImpl('field'), | ||
| new Impl.LiteralImpl(LiteralType.String, "'abc'") | ||
| ); | ||
| expect(actual).toEqual(expected); | ||
| }); | ||
| it('return field, LIKE keyword, and value separated by spaces for toSoqlSyntax()', () => { | ||
| const expected = `field LIKE 'abc'`; | ||
| const actual = new Impl.LikeConditionImpl( | ||
| new Impl.FieldRefImpl('field'), | ||
| new Impl.LiteralImpl(LiteralType.String, "'abc'") | ||
| ).toSoqlSyntax(); | ||
| expect(actual).toEqual(expected); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * Copyright (c) 2020, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import * as Soql from '../model'; | ||
| import { SoqlModelObjectImpl } from './soqlModelObjectImpl'; | ||
|
|
||
| export class LikeConditionImpl extends SoqlModelObjectImpl implements Soql.LikeCondition { | ||
| public constructor(public field: Soql.Field, public compareValue: Soql.CompareValue) { | ||
| super(); | ||
| } | ||
| public toSoqlSyntax(options?: Soql.SyntaxOptions): string { | ||
| return `${this.field.toSoqlSyntax(options)} LIKE ${this.compareValue.toSoqlSyntax(options)}`; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.jsis indicative of how the model is created. For raw JSON,deserializer.test.tshas lots of examples of what these different conditions look like when modeled in a WHERE clause.