-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add regex support to only
and except
table filters
#278
Conversation
aaf8fdd
to
accfff2
Compare
This is fantastic! Great work!!!
The sqlite driver allows us to register functions. This should enable us add regexp support func registerRegexpFunction() error {
return sqlite.RegisterScalarFunction("regexp", 2, func(
ctx *sqlite.FunctionContext,
args []sqlDriver.Value,
) (sqlDriver.Value, error) {
if len(args) != 2 {
return nil, fmt.Errorf("expected 2 arguments, got %d", len(args))
}
re, ok := args[0].(string)
if !ok {
return nil, fmt.Errorf("expected string, got %T", args[0])
}
s, ok := args[1].(string)
if !ok {
return nil, fmt.Errorf("expected string, got %T", args[1])
}
match, err := regexp.MatchString(re, s)
if err != nil {
return nil, err
}
return match, nil
})
} Can you add this so that this is supported across the 3 primary drivers? |
accfff2
to
183d15e
Compare
Thank you for providing the I've added the requested changes to the SQLite driver implementation. However, the newly added tests uncovered a (presumably old) issue: the Would you like this addressed in the current PR, or do you prefer a separate PR for this? |
|
Sure, basically I have the following table schema: CREATE TABLE foo_bar (
id INTEGER PRIMARY KEY AUTOINCREMENT,
secret_col TEXT NOT NULL
);
CREATE TABLE foo_baz (
id INTEGER PRIMARY KEY AUTOINCREMENT,
secret_col TEXT NOT NULL
); And I also have the following configuration: sqlite:
except:
"*":
- secret_col I expect I'll go ahead and fix it directly in this PR.. |
183d15e
to
aa8f881
Compare
All fixed and ready for review I believe 🙂 |
aa8f881
to
c9e6cc7
Compare
Resolves #256
This pull request adds regex support to the
only
andexcept
table filters.bobgen.yaml
now allows writing expressions such as:These are only made available for the PostgreSQL and MySQL drivers, as SQLite doesn't support regular expressions out of the box (it requires loading an extension).
The proposed regex delimiter syntax (enclosing the regular expressions with forward slashes) borrows its concept from languages such as JavaScript, PHP, and Perl. The idea is to keep the old
IN
/NOT IN
logic intact while complementing it with additional regular expression matching logic whenever explicitly requested.I've added a few additional test cases to ensure that all filtering combinations work as expected (the tradeoff here, though, is that the number of golden files committed to the repository has increased significantly).
I remain open to feedback and suggestions for further improvements.