forked from G-Research/fasttrackml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to use regular expressions in Aim search queries (G-Resea…
…rch#171) Co-authored-by: Jonathan Giannuzzi <jgiannuzzi@users.noreply.github.com>
- Loading branch information
1 parent
607bc42
commit 7340019
Showing
9 changed files
with
258 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 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 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,38 @@ | ||
package query | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gorm.io/driver/postgres" | ||
"gorm.io/gorm/clause" | ||
) | ||
|
||
// Regexp whether string matches regular expression | ||
type Regexp struct { | ||
clause.Eq | ||
Dialector string | ||
} | ||
|
||
// Build builds positive statement. | ||
func (regexp Regexp) Build(builder clause.Builder) { | ||
builder.WriteQuoted(regexp.Column) | ||
switch regexp.Dialector { | ||
case postgres.Dialector{}.Name(): | ||
builder.WriteString(" ~ ") | ||
default: | ||
builder.WriteString(" regexp ") | ||
} | ||
builder.AddVar(builder, fmt.Sprintf("%s", regexp.Value)) | ||
} | ||
|
||
// NegationBuild builds negative statement. | ||
func (regexp Regexp) NegationBuild(builder clause.Builder) { | ||
builder.WriteQuoted(regexp.Column) | ||
switch regexp.Dialector { | ||
case postgres.Dialector{}.Name(): | ||
builder.WriteString(" !~ ") | ||
default: | ||
builder.WriteString(" NOT regexp ") | ||
} | ||
builder.AddVar(builder, regexp.Value) | ||
} |
This file contains 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 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
Oops, something went wrong.