Skip to content

Commit

Permalink
chore: support find
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Nov 1, 2024
1 parent ae474bd commit 9185187
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/formula/src/formula/formula.registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,14 @@ globalFormulaRegistry.register(
["SWITCH({{field1}}, 1, 'one', 2, 'two', 3, 'three')", undefined],
],
)

globalFormulaRegistry.register(
"FIND",
[["string", "string"]],
"number",
"Returns the position of a substring within a string.",
[
["FIND('Hello', 'e')", 1],
["FIND({{field1}}, 'e')", undefined],
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export class UnderlyingFormulaVisitor extends FormulaParserVisitor<string> {
sql += ` ELSE ${this.visit(defaultValue)} END`
return `(${sql})`
})
.with("FIND", () => {
const args = this.arguments(ctx)
return `(INSTR(LOWER(${args[1]}), LOWER(${args[0]})))`
})
.with("ADD", "SUM", () => {
const fn = this.arguments(ctx).join(" + ")
return `(${fn})`
Expand Down

0 comments on commit 9185187

Please sign in to comment.