Skip to content

Commit

Permalink
WIP fixing chained .limit() on cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
dill0wn committed Jul 9, 2024
1 parent 1666e11 commit 801c5be
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ming/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import warnings
from collections import defaultdict
from datetime import datetime
# from typing import Iterable, Sequence
from collections.abc import Sequence

import bson
from bson import Decimal128
Expand Down Expand Up @@ -74,7 +76,7 @@ def __init__(self, cls, cursor, allow_extra=True, strip_extra=True, find_spec=No
self.cursor = cursor
self._allow_extra = allow_extra
self._strip_extra = strip_extra
self.find_spec = find_spec
self.find_spec = find_spec or {}

def __iter__(self):
return self
Expand All @@ -96,10 +98,12 @@ def distinct(self, *args, **kwargs):
return self.cursor.distinct(*args, **kwargs)

def limit(self, limit):
self.find_spec['limit'] = limit
self.cursor = self.cursor.limit(limit)
return self

def skip(self, skip):
self.find_spec['skip'] = skip
self.cursor = self.cursor.skip(skip)
return self

Expand All @@ -108,6 +112,12 @@ def hint(self, index_or_name):
return self

def sort(self, *args, **kwargs):
if args:
if isinstance(args[0], list):
sort = args[0]
else:
sort = args
self.find_spec['sort'] = sort
self.cursor = self.cursor.sort(*args, **kwargs)
return self

Expand Down

0 comments on commit 801c5be

Please sign in to comment.