Skip to content

INTPYTHON-348 add support for QuerySet.raw_mql() #173

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions django_mongodb/manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.db.models.manager import BaseManager
from .query import MongoQuerySet


class MongoManager(BaseManager.from_queryset(MongoQuerySet)):
def get_query_set(self):
return MongoQuerySet(self.model, using=self._db)
21 changes: 19 additions & 2 deletions django_mongodb/query.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from functools import reduce, wraps
from operator import add as add_operator
from collections.abc import Mapping

from django.core.exceptions import EmptyResultSet, FullResultSet
from django.db import DatabaseError, IntegrityError, NotSupportedError
from django.db import DatabaseError, IntegrityError, NotSupportedError, connections
from django.db.models import QuerySet
from django.db.models.expressions import Case, Col, When
from django.db.models.functions import Mod
from django.db.models.lookups import Exact
from django.db.models.sql.constants import INNER
from django.db.models.query import BaseIterable
from django.db.models.sql.constants import INNER, GET_ITERATOR_CHUNK_SIZE
from django.db.models.sql.datastructures import Join
from django.db.models.sql.where import AND, OR, XOR, ExtraWhere, NothingNode, WhereNode
from django.db.models.sql import Query
from django.utils.functional import cached_property
from pymongo.errors import BulkWriteError, DuplicateKeyError, PyMongoError


Expand Down Expand Up @@ -307,3 +312,15 @@ def register_nodes():
Join.as_mql = join
NothingNode.as_mql = NothingNode.as_sql
WhereNode.as_mql = where_node


class MongoQuerySet(QuerySet):
def raw_mql(self, raw_query):
return QuerySet(self.model, RawQuery(self.model, raw_query))


class RawQuery(Query):

def __init__(self, model, raw_query):
super(RawQuery, self).__init__(model)
self.raw_query = raw_query
Loading