mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-30 14:56:19 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
89 lines
2.5 KiB
Go
89 lines
2.5 KiB
Go
package matcher
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/temporalio/sqlparser"
|
|
)
|
|
|
|
type Evaluator interface {
|
|
Evaluate(query string) (bool, error)
|
|
}
|
|
|
|
func getWhereCause(query string) (sqlparser.Expr, error) {
|
|
stmt, err := sqlparser.Parse(query)
|
|
if err != nil {
|
|
return nil, NewMatcherError("%s: %v", malformedSqlQueryErrMessage, err)
|
|
}
|
|
|
|
selectStmt, isSelect := stmt.(*sqlparser.Select)
|
|
if !isSelect {
|
|
return nil, NewMatcherError("%s: statement must be 'select' not %T", notSupportedErrMessage, stmt)
|
|
}
|
|
|
|
if selectStmt.Limit != nil {
|
|
return nil, NewMatcherError("%s: 'limit' clause", notSupportedErrMessage)
|
|
}
|
|
|
|
if selectStmt.Where == nil {
|
|
return nil, NewMatcherError("%s: 'where' clause is missing", notSupportedErrMessage)
|
|
}
|
|
|
|
return selectStmt.Where.Expr, nil
|
|
}
|
|
|
|
func prepareQuery(query string) (string, error) {
|
|
query = strings.TrimSpace(query)
|
|
if query == "" {
|
|
return "", nil
|
|
}
|
|
|
|
if strings.HasPrefix(strings.ToLower(query), "where ") ||
|
|
strings.HasPrefix(strings.ToLower(query), "select ") {
|
|
return "", fmt.Errorf("invalid filter: %s", query)
|
|
}
|
|
|
|
// sqlparser can't parse just WHERE clause but instead accepts only valid SQL statement.
|
|
query = fmt.Sprintf("select * from table1 where %s", query)
|
|
|
|
return query, nil
|
|
}
|
|
|
|
func compareQueryString(inStr string, expectedStr string, operation string, fieldName string) (bool, error) {
|
|
if len(inStr) == 0 {
|
|
return false, NewMatcherError("%s cannot be empty", fieldName)
|
|
}
|
|
switch operation {
|
|
case sqlparser.EqualStr:
|
|
return expectedStr == inStr, nil
|
|
case sqlparser.NotEqualStr:
|
|
return expectedStr != inStr, nil
|
|
case sqlparser.StartsWithStr:
|
|
return strings.HasPrefix(expectedStr, inStr), nil
|
|
case sqlparser.NotStartsWithStr:
|
|
return !strings.HasPrefix(expectedStr, inStr), nil
|
|
default:
|
|
return false, NewMatcherError("%s: operation %s is not supported for %s filter", invalidExpressionErrMessage, operation, fieldName)
|
|
}
|
|
}
|
|
|
|
func compareQueryInt(inVal int, expectedVal int, operation string, fieldName string) (bool, error) {
|
|
switch operation {
|
|
case sqlparser.EqualStr:
|
|
return inVal == expectedVal, nil
|
|
case sqlparser.NotEqualStr:
|
|
return inVal != expectedVal, nil
|
|
case sqlparser.GreaterThanStr:
|
|
return expectedVal > inVal, nil
|
|
case sqlparser.GreaterEqualStr:
|
|
return expectedVal >= inVal, nil
|
|
case sqlparser.LessThanStr:
|
|
return expectedVal < inVal, nil
|
|
case sqlparser.LessEqualStr:
|
|
return expectedVal <= inVal, nil
|
|
default:
|
|
return false, NewMatcherError("%s: operation %s is not supported for %s filter", invalidExpressionErrMessage, operation, fieldName)
|
|
}
|
|
}
|