-
-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2c667e
commit 2a3cf0d
Showing
6 changed files
with
42 additions
and
7 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,25 @@ | ||
from tortoise.contrib import test | ||
from tests import testmodels | ||
|
||
@test.requireCapability(dialect="postgres") | ||
class TestPosixRegexFilterPostgres(test.IsolatedTestCase): | ||
tortoise_test_modules = ["tests.testmodels"] | ||
|
||
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)), | ||
{"Johann Wolfgang von Goethe"}, | ||
) | ||
|
||
|
||
@test.requireCapability(dialect="mysql") | ||
class TestPosixRegexFilterPostgres(test.IsolatedTestCase): | ||
tortoise_test_modules = ["tests.testmodels"] | ||
|
||
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)), | ||
{"Johann Wolfgang von Goethe"}, | ||
) |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
from pypika.terms import Term, BasicCriterion | ||
from pypika.enums import Comparator | ||
|
||
class PostgresRegexMatching(Comparator): | ||
posix_regex = " ~ " | ||
|
||
def posix_regex(field: Term, value: str): | ||
return BasicCriterion(" ~ ", field, value) | ||
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