MCPcopy
hub / github.com/ormar-orm/ormar / values

Method values

ormar/queryset/queryset.py:668–729  ·  view source on GitHub ↗

Return a list of dictionaries with column values in order of the fields passed or all fields from queried models. To filter for given row use filter/exclude methods before values, to limit number of rows use limit/offset or paginate before values. Note that

(
        self,
        fields: Union[list, str, set, dict, None] = None,
        exclude_through: bool = False,
        _as_dict: bool = True,
        _flatten: bool = False,
    )

Source from the content-addressed store, hash-verified

666 return self.rebuild_self(order_bys=order_bys)
667
668 async def values(
669 self,
670 fields: Union[list, str, set, dict, None] = None,
671 exclude_through: bool = False,
672 _as_dict: bool = True,
673 _flatten: bool = False,
674 ) -> list:
675 """
676 Return a list of dictionaries with column values in order of the fields
677 passed or all fields from queried models.
678
679 To filter for given row use filter/exclude methods before values,
680 to limit number of rows use limit/offset or paginate before values.
681
682 Note that it always return a list even for one row from database.
683
684 :param exclude_through: flag if through models should be excluded
685 :type exclude_through: bool
686 :param _flatten: internal parameter to flatten one element tuples
687 :type _flatten: bool
688 :param _as_dict: internal parameter if return dict or tuples
689 :type _as_dict: bool
690 :param fields: field name or list of field names to extract from db
691 :type fields: Union[list, str, set, dict]
692 """
693 if fields:
694 return await self.fields(columns=fields).values(
695 _as_dict=_as_dict, _flatten=_flatten, exclude_through=exclude_through
696 )
697 excludable = self._excludable.with_projection_exclusions(
698 source_model=self.model,
699 select_related=self._select_related,
700 )
701 projected = (
702 self
703 if excludable is self._excludable
704 else self.rebuild_self(excludable=excludable)
705 )
706 expr = projected.build_select_expression()
707 async with self.model_config.database.get_query_executor() as executor:
708 rows = await executor.fetch_all(expr)
709 if not rows:
710 return []
711 alias_resolver = ReverseAliasResolver(
712 select_related=self._select_related,
713 excludable=excludable,
714 model_cls=self.model_cls, # type: ignore
715 exclude_through=exclude_through,
716 )
717 column_map = alias_resolver.resolve_columns(columns_names=list(rows[0].keys())) # type: ignore
718 result = [
719 {column_map.get(k): v for k, v in dict(x).items() if k in column_map}
720 for x in rows
721 ]
722 if _as_dict:
723 return result
724 if _flatten and self._excludable.include_entry_count() != 1:
725 raise QueryDefinitionError(

Calls 11

fieldsMethod · 0.95
rebuild_selfMethod · 0.95
resolve_columnsMethod · 0.95
get_query_executorMethod · 0.80
fetch_allMethod · 0.80
include_entry_countMethod · 0.80
getMethod · 0.45