コード例 #1
0
 def _clone(self):
     # yes, a little embarassing here.
     # go look at 0.4 for the simple version.
     q = Query.__new__(Query)
     q.mapper = self.mapper
     q.select_mapper = self.select_mapper
     q._order_by = self._order_by
     q._distinct = self._distinct
     q._entities = list(self._entities)
     q.always_refresh = self.always_refresh
     q.with_options = list(self.with_options)
     q._session = self.session
     q.is_polymorphic = self.is_polymorphic
     q.lockmode = self.lockmode
     q.extension = mapper._ExtensionCarrier()
     for ext in self.extension:
         q.extension.append(ext)
     q._offset = self._offset
     q._limit = self._limit
     q._params = self._params
     q._group_by = self._group_by
     q._get_clause = self._get_clause
     q._from_obj = list(self._from_obj)
     q._joinpoint = self._joinpoint
     q._criterion = self._criterion
     q._statement = self._statement
     q._col = self._col
     q._func = self._func
     return q
コード例 #2
0
    def __init__(self, class_or_mapper, session=None, entity_name=None, lockmode=None, with_options=None, extension=None, **kwargs):
        if isinstance(class_or_mapper, type):
            self.mapper = mapper.class_mapper(class_or_mapper, entity_name=entity_name)
        else:
            self.mapper = class_or_mapper.compile()
        self.with_options = with_options or []
        self.select_mapper = self.mapper.get_select_mapper().compile()
        self.always_refresh = kwargs.pop('always_refresh', self.mapper.always_refresh)
        self.lockmode = lockmode
        self.extension = mapper._ExtensionCarrier()
        if extension is not None:
            self.extension.append(extension)
        self.extension.append(self.mapper.extension)
        self.is_polymorphic = self.mapper is not self.select_mapper
        self._session = session
        if not hasattr(self.mapper, '_get_clause'):
            _get_clause = sql.and_()
            for primary_key in self.primary_key_columns:
                _get_clause.clauses.append(primary_key == sql.bindparam(primary_key._label, type=primary_key.type, unique=True))
            self.mapper._get_clause = _get_clause
            
        self._entities = []
        self._get_clause = self.mapper._get_clause

        self._order_by = kwargs.pop('order_by', False)
        self._group_by = kwargs.pop('group_by', False)
        self._distinct = kwargs.pop('distinct', False)
        self._offset = kwargs.pop('offset', None)
        self._limit = kwargs.pop('limit', None)
        self._criterion = None
        self._joinpoint = self.mapper
        self._from_obj = [self.table]

        for opt in util.flatten_iterator(self.with_options):
            opt.process_query(self)
コード例 #3
0
 def _clone(self):
     q = Query.__new__(Query)
     q.mapper = self.mapper
     q.select_mapper = self.select_mapper
     q._order_by = self._order_by
     q._distinct = self._distinct
     q._entities = list(self._entities)
     q.always_refresh = self.always_refresh
     q.with_options = list(self.with_options)
     q._session = self.session
     q.is_polymorphic = self.is_polymorphic
     q.lockmode = self.lockmode
     q.extension = mapper._ExtensionCarrier()
     for ext in self.extension:
         q.extension.append(ext)
     q._offset = self._offset
     q._limit = self._limit
     q._group_by = self._group_by
     q._get_clause = self._get_clause
     q._from_obj = list(self._from_obj)
     q._joinpoint = self._joinpoint
     q._criterion = self._criterion
     return q