-
Notifications
You must be signed in to change notification settings - Fork 67
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
Showing
17 changed files
with
561 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from motorengine.query.base import QueryOperator | ||
|
||
|
||
class ContainsOperator(QueryOperator): | ||
''' | ||
Query operator used to return all documents which specified field contains a string equal to a passed value. | ||
It is case sensitive. | ||
For more information on `$regex` go to https://docs.mongodb.org/manual/reference/operator/query/regex/ | ||
Usage: | ||
.. testsetup:: contains_query_operator | ||
from datetime import datetime | ||
import tornado.ioloop | ||
from motorengine import * | ||
.. testcode:: contains_query_operator | ||
class User(Document): | ||
first_name = StringField() | ||
query = Q(first_name__contains='nar') | ||
query_result = query.to_query(User) | ||
print(query_result) | ||
The resulting query is: | ||
.. testoutput:: contains_query_operator | ||
{'name': {'$regex': 'nar'}} | ||
''' | ||
|
||
def to_query(self, field_name, value): | ||
return { | ||
field_name: {"$regex": r'%s' %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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from motorengine.query.base import QueryOperator | ||
|
||
|
||
class EndsWithOperator(QueryOperator): | ||
''' | ||
Query operator used to return all documents which specified field ends with passed string value. | ||
It is case sensitive. | ||
For more information on `$regex` go to https://docs.mongodb.org/manual/reference/operator/query/regex/ | ||
Usage: | ||
.. testsetup:: endswith_query_operator | ||
from datetime import datetime | ||
import tornado.ioloop | ||
from motorengine import * | ||
.. testcode:: endswith_query_operator | ||
class User(Document): | ||
first_name = StringField() | ||
query = Q(first_name__endswith='do') | ||
query_result = query.to_query(User) | ||
print(query_result) | ||
The resulting query is: | ||
.. testoutput:: endswith_query_operator | ||
{'name': {'$regex': 'do$'}} | ||
''' | ||
|
||
def to_query(self, field_name, value): | ||
return { | ||
field_name: {"$regex": r'%s$' %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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from motorengine.query.base import QueryOperator | ||
|
||
|
||
class ExactOperator(QueryOperator): | ||
''' | ||
Query operator used to return all documents which specified field is exactly as passed string value. | ||
It is case sensitive. | ||
For more information on `$regex` go to https://docs.mongodb.org/manual/reference/operator/query/regex/ | ||
Usage: | ||
.. testsetup:: exact_query_operator | ||
from datetime import datetime | ||
import tornado.ioloop | ||
from motorengine import * | ||
.. testcode:: exact_query_operator | ||
class User(Document): | ||
first_name = StringField() | ||
query = Q(first_name__exact='Bernardo') | ||
query_result = query.to_query(User) | ||
print(query_result) | ||
The resulting query is: | ||
.. testoutput:: exact_query_operator | ||
{'name': {'$regex': '^Bernardo$'}} | ||
''' | ||
|
||
def to_query(self, field_name, value): | ||
return { | ||
field_name: {"$regex": r'^%s$' %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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from motorengine.query.base import QueryOperator | ||
|
||
|
||
class IContainsOperator(QueryOperator): | ||
''' | ||
Query operator used to return all documents which specified field contains a string equal to a passed value. | ||
It is not case sensitive. | ||
For more information on `$regex` go to https://docs.mongodb.org/manual/reference/operator/query/regex/ | ||
Usage: | ||
.. testsetup:: icontains_query_operator | ||
from datetime import datetime | ||
import tornado.ioloop | ||
from motorengine import * | ||
.. testcode:: icontains_query_operator | ||
class User(Document): | ||
first_name = StringField() | ||
query = Q(first_name__icontains='NaR') | ||
query_result = query.to_query(User) | ||
print(query_result) | ||
The resulting query is: | ||
.. testoutput:: icontains_query_operator | ||
{'name': {'$regex': 'NaR', '$options': 'i'}} | ||
''' | ||
|
||
def to_query(self, field_name, value): | ||
return { | ||
field_name: { | ||
"$regex": r'%s' %value, | ||
"$options": 'i' | ||
} | ||
} |
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,50 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from motorengine.query.base import QueryOperator | ||
|
||
|
||
class IEndsWithOperator(QueryOperator): | ||
''' | ||
Query operator used to return all documents which specified field ends with passed string value. | ||
It is not case sensitive. | ||
For more information on `$regex` go to https://docs.mongodb.org/manual/reference/operator/query/regex/ | ||
Usage: | ||
.. testsetup:: iendswith_query_operator | ||
from datetime import datetime | ||
import tornado.ioloop | ||
from motorengine import * | ||
.. testcode:: iendswith_query_operator | ||
class User(Document): | ||
first_name = StringField() | ||
query = Q(first_name__iendswith='Do') | ||
query_result = query.to_query(User) | ||
print(query_result) | ||
The resulting query is: | ||
.. testoutput:: iendswith_query_operator | ||
{'name': {'$regex': 'Do$', '$options': 'i'}} | ||
''' | ||
|
||
def to_query(self, field_name, value): | ||
return { | ||
field_name: { | ||
"$regex": r'%s$' %value, | ||
"$options": 'i' | ||
} | ||
} |
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,50 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from motorengine.query.base import QueryOperator | ||
|
||
|
||
class IExactOperator(QueryOperator): | ||
''' | ||
Query operator used to return all documents which specified field is exactly as passed string value. | ||
It is not case sensitive. | ||
For more information on `$regex` go to https://docs.mongodb.org/manual/reference/operator/query/regex/ | ||
Usage: | ||
.. testsetup:: iexact_query_operator | ||
from datetime import datetime | ||
import tornado.ioloop | ||
from motorengine import * | ||
.. testcode:: iexact_query_operator | ||
class User(Document): | ||
first_name = StringField() | ||
query = Q(first_name__iexact='bErNaRdO') | ||
query_result = query.to_query(User) | ||
print(query_result) | ||
The resulting query is: | ||
.. testoutput:: iexact_query_operator | ||
{'name': {'$regex': '^bErNaRdO$', '$options': 'i'}} | ||
''' | ||
|
||
def to_query(self, field_name, value): | ||
return { | ||
field_name: { | ||
"$regex": r'^%s$' %value, | ||
"$options": 'i' | ||
} | ||
} |
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,50 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from motorengine.query.base import QueryOperator | ||
|
||
|
||
class IStartsWithOperator(QueryOperator): | ||
''' | ||
Query operator used to return all documents which specified field starts with passed string value. | ||
It is not case sensitive. | ||
For more information on `$regex` go to https://docs.mongodb.org/manual/reference/operator/query/regex/ | ||
Usage: | ||
.. testsetup:: istartswith_query_operator | ||
from datetime import datetime | ||
import tornado.ioloop | ||
from motorengine import * | ||
.. testcode:: istartswith_query_operator | ||
class User(Document): | ||
first_name = StringField() | ||
query = Q(first_name__istartswith='bEr') | ||
query_result = query.to_query(User) | ||
print(query_result) | ||
The resulting query is: | ||
.. testoutput:: istartswith_query_operator | ||
{'name': {'$regex': '^bEr', '$options': 'i'}} | ||
''' | ||
|
||
def to_query(self, field_name, value): | ||
return { | ||
field_name: { | ||
"$regex": r'^%s' %value, | ||
"$options": 'i' | ||
} | ||
} |
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,47 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from motorengine.query.base import QueryOperator | ||
|
||
|
||
class StartsWithOperator(QueryOperator): | ||
''' | ||
Query operator used to return all documents which specified field starts with passed string value. | ||
It is case sensitive. | ||
For more information on `$regex` go to https://docs.mongodb.org/manual/reference/operator/query/regex/ | ||
Usage: | ||
.. testsetup:: startswith_query_operator | ||
from datetime import datetime | ||
import tornado.ioloop | ||
from motorengine import * | ||
.. testcode:: startswith_query_operator | ||
class User(Document): | ||
first_name = StringField() | ||
query = Q(first_name__startswith='Ber') | ||
query_result = query.to_query(User) | ||
print(query_result) | ||
The resulting query is: | ||
.. testoutput:: startswith_query_operator | ||
{'name': {'$regex': '^Ber'}} | ||
''' | ||
|
||
def to_query(self, field_name, value): | ||
return { | ||
field_name: {"$regex": r'^%s' %value} | ||
} |
Oops, something went wrong.