-
-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add POSIX Regex support for PostgreSQL and MySQL (#1714)
* add posix regex filter operator for postgresql and mysql * update docs * add tests * adjust tests * apply formatting with make styles * fix mypy issue
- Loading branch information
1 parent
d1c4e0e
commit d601ba0
Showing
6 changed files
with
69 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from tests import testmodels | ||
from tortoise.contrib import test | ||
|
||
|
||
class TestPosixRegexFilter(test.TestCase): | ||
|
||
@test.requireCapability(dialect="mysql") | ||
@test.requireCapability(dialect="postgres") | ||
async def test_regex_filter(self): | ||
author = await testmodels.Author.create(name="Johann Wolfgang von Goethe") | ||
self.assertEqual( | ||
set( | ||
await testmodels.Author.filter( | ||
name__posix_regex="^Johann [a-zA-Z]+ von Goethe$" | ||
).values_list("name", flat=True) | ||
), | ||
{author.name}, | ||
) |
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,11 @@ | ||
import enum | ||
|
||
from pypika.terms import BasicCriterion, Term | ||
|
||
|
||
class PostgresRegexMatching(enum.Enum): | ||
posix_regex = "~" | ||
|
||
|
||
def postgres_posix_regex(field: Term, value: str): | ||
return BasicCriterion(PostgresRegexMatching.posix_regex, field, field.wrap_constant(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