當前位置: 首頁>>代碼示例>>Python>>正文


Python sql.compiler方法代碼示例

本文整理匯總了Python中django.db.models.sql.compiler方法的典型用法代碼示例。如果您正苦於以下問題:Python sql.compiler方法的具體用法?Python sql.compiler怎麽用?Python sql.compiler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.db.models.sql的用法示例。


在下文中一共展示了sql.compiler方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __iter__

# 需要導入模塊: from django.db.models import sql [as 別名]
# 或者: from django.db.models.sql import compiler [as 別名]
def __iter__(self):
        """
        The queryset iterator protocol uses three nested iterators in the
        default case:
            1. sql.compiler:execute_sql()
               - Returns 100 rows at time (constants.GET_ITERATOR_CHUNK_SIZE)
                 using cursor.fetchmany(). This part is responsible for
                 doing some column masking, and returning the rows in chunks.
            2. sql/compiler.results_iter()
               - Returns one row at time. At this point the rows are still just
                 tuples. In some cases the return values are converted to
                 Python values at this location.
            3. self.iterator()
               - Responsible for turning the rows into model objects.
        """
        self._fetch_all()
        return iter(self._result_cache) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:19,代碼來源:query.py

示例2: __iter__

# 需要導入模塊: from django.db.models import sql [as 別名]
# 或者: from django.db.models.sql import compiler [as 別名]
def __iter__(self):
        queryset = self.queryset
        query = queryset.query
        compiler = query.get_compiler(queryset.db)

        if queryset._fields:
            field_names = list(query.values_select)
            extra_names = list(query.extra_select)
            annotation_names = list(query.annotation_select)

            # extra(select=...) cols are always at the start of the row.
            names = extra_names + field_names + annotation_names

            fields = list(queryset._fields) + [f for f in annotation_names if f not in queryset._fields]
            if fields != names:
                # Reorder according to fields.
                index_map = {name: idx for idx, name in enumerate(names)}
                rowfactory = operator.itemgetter(*[index_map[f] for f in fields])
                return map(
                    rowfactory,
                    compiler.results_iter(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
                )
        return compiler.results_iter(tuple_expected=True, chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:25,代碼來源:query.py

示例3: __iter__

# 需要導入模塊: from django.db.models import sql [as 別名]
# 或者: from django.db.models.sql import compiler [as 別名]
def __iter__(self):
        queryset = self.queryset
        query = queryset.query
        compiler = query.get_compiler(queryset.db)

        if not query.extra_select and not query.annotation_select:
            for row in compiler.results_iter():
                yield tuple(row)
        else:
            field_names = list(query.values_select)
            extra_names = list(query.extra_select)
            annotation_names = list(query.annotation_select)

            # extra(select=...) cols are always at the start of the row.
            names = extra_names + field_names + annotation_names

            if queryset._fields:
                # Reorder according to fields.
                fields = list(queryset._fields) + [f for f in annotation_names if f not in queryset._fields]
            else:
                fields = names

            for row in compiler.results_iter():
                data = dict(zip(names, row))
                yield tuple(data[f] for f in fields) 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:27,代碼來源:query.py

示例4: iterator

# 需要導入模塊: from django.db.models import sql [as 別名]
# 或者: from django.db.models.sql import compiler [as 別名]
def iterator(self):
        compiler = self.query.get_compiler(self.db)
        if self.flat and len(self._fields) == 1:
            for row in compiler.results_iter():
                yield row[0]
        elif not self.query.extra_select and not self.query.annotation_select:
            for row in compiler.results_iter():
                yield tuple(row)
        else:
            # When extra(select=...) or an annotation is involved, the extra
            # cols are always at the start of the row, and we need to reorder
            # the fields to match the order in self._fields.
            extra_names = list(self.query.extra_select)
            field_names = self.field_names
            annotation_names = list(self.query.annotation_select)

            names = extra_names + field_names + annotation_names

            # If a field list has been specified, use it. Otherwise, use the
            # full list of fields, including extras and annotations.
            if self._fields:
                fields = list(self._fields) + [f for f in annotation_names if f not in self._fields]
            else:
                fields = names

            for row in compiler.results_iter():
                data = dict(zip(names, row))
                yield tuple(data[f] for f in fields) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:30,代碼來源:query.py


注:本文中的django.db.models.sql.compiler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。