Skip to content

Commit

Permalink
Merge pull request #250 from balena-io-modules/add-typings
Browse files Browse the repository at this point in the history
Adds `EndsWithNode` and `ContainsNode` typings
  • Loading branch information
Page- authored Jun 12, 2024
2 parents f4cad6e + bb22332 commit ac98df1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/AbstractSQLCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export type NotNode = ['Not', BooleanTypeNodes];
export type AndNode = ['And', ...BooleanTypeNodes[]];
export type OrNode = ['Or', ...BooleanTypeNodes[]];
export type StartsWithNode = ['StartsWith', TextTypeNodes, TextTypeNodes];
export type EndsWithNode = ['EndsWith', TextTypeNodes, TextTypeNodes];
export type ContainsNode = ['Contains', TextTypeNodes, TextTypeNodes];
export type StrictBooleanTypeNodes =
| BooleanNode
| EqualsNode
Expand All @@ -103,7 +105,9 @@ export type StrictBooleanTypeNodes =
| NotNode
| AndNode
| OrNode
| StartsWithNode;
| StartsWithNode
| EndsWithNode
| ContainsNode;
export type BooleanTypeNodes = StrictBooleanTypeNodes | UnknownTypeNodes;

export type YearNode = ['Year', DateTypeNodes];
Expand Down
25 changes: 14 additions & 11 deletions src/AbstractSQLOptimiser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,18 @@ const SubtractDateMatcher = tryMatches<
),
);

const EndsWithMatcher = rewriteMatch(
'Endswith',
[TextValue, TextValue],
Helper<MatchFn<LikeNode>>(
([haystack, needle]: [TextTypeNodes, TextTypeNodes]) => [
'Like',
haystack,
['Concatenate', ['EmbeddedText', '%'], ['EscapeForLike', needle]],
],
),
);

const typeRules = {
UnionQuery: (args): UnionQueryNode => {
checkMinArgs('UnionQuery', args, 2);
Expand Down Expand Up @@ -1552,17 +1564,8 @@ const typeRules = {
],
),
),
Endswith: rewriteMatch(
'Endswith',
[TextValue, TextValue],
Helper<MatchFn<LikeNode>>(
([haystack, needle]: [TextTypeNodes, TextTypeNodes]) => [
'Like',
haystack,
['Concatenate', ['EmbeddedText', '%'], ['EscapeForLike', needle]],
],
),
),
Endswith: EndsWithMatcher,
EndsWith: EndsWithMatcher,
IndexOf: rewriteMatch(
'IndexOf',
[TextValue, TextValue],
Expand Down

0 comments on commit ac98df1

Please sign in to comment.