当前位置: 首页>>代码示例>>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;未经允许,请勿转载。