Skip to content

Commit

Permalink
Merge 389ca9b into d3538bd
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaawwaa committed Jan 13, 2016
2 parents d3538bd + 389ca9b commit 95df405
Show file tree
Hide file tree
Showing 17 changed files with 561 additions and 0 deletions.
47 changes: 47 additions & 0 deletions motorengine/query/contains.py
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}
}
47 changes: 47 additions & 0 deletions motorengine/query/ends_with.py
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}
}
47 changes: 47 additions & 0 deletions motorengine/query/exact.py
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}
}
50 changes: 50 additions & 0 deletions motorengine/query/i_contains.py
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'
}
}
50 changes: 50 additions & 0 deletions motorengine/query/i_ends_with.py
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'
}
}
50 changes: 50 additions & 0 deletions motorengine/query/i_exact.py
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'
}
}
50 changes: 50 additions & 0 deletions motorengine/query/i_starts_with.py
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'
}
}
47 changes: 47 additions & 0 deletions motorengine/query/starts_with.py
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}
}

0 comments on commit 95df405

Please sign in to comment.