MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / MappingResult

Class MappingResult

lib/sqlalchemy/engine/result.py:1589–1728  ·  view source on GitHub ↗

A wrapper for a :class:`_engine.Result` that returns dictionary values rather than :class:`_engine.Row` values. The :class:`_engine.MappingResult` object is acquired by calling the :meth:`_engine.Result.mappings` method.

Source from the content-addressed store, hash-verified

1587
1588
1589class MappingResult(_WithKeys, FilterResult[RowMapping]):
1590 """A wrapper for a :class:`_engine.Result` that returns dictionary values
1591 rather than :class:`_engine.Row` values.
1592
1593 The :class:`_engine.MappingResult` object is acquired by calling the
1594 :meth:`_engine.Result.mappings` method.
1595
1596 """
1597
1598 __slots__ = ()
1599
1600 _generate_rows = True
1601
1602 _post_creational_filter = operator.attrgetter("_mapping")
1603
1604 def __init__(self, result: Result[Unpack[TupleAny]]):
1605 self._real_result = result
1606 self._unique_filter_state = result._unique_filter_state
1607 self._metadata = result._metadata
1608 if result._source_supports_scalars:
1609 self._metadata = self._metadata._reduce([0])
1610
1611 def unique(self, strategy: Optional[_UniqueFilterType] = None) -> Self:
1612 """Apply unique filtering to the objects returned by this
1613 :class:`_engine.MappingResult`.
1614
1615 See :meth:`_engine.Result.unique` for usage details.
1616
1617 """
1618 self._unique_filter_state = (set(), strategy)
1619 return self
1620
1621 def columns(self, *col_expressions: _KeyIndexType) -> Self:
1622 """Establish the columns that should be returned in each row."""
1623 return self._column_slices(col_expressions)
1624
1625 def partitions(
1626 self, size: Optional[int] = None
1627 ) -> Iterator[Sequence[RowMapping]]:
1628 """Iterate through sub-lists of elements of the size given.
1629
1630 Equivalent to :meth:`_engine.Result.partitions` except that
1631 :class:`_engine.RowMapping` values, rather than :class:`_engine.Row`
1632 objects, are returned.
1633
1634 """
1635
1636 getter = self._manyrow_getter
1637
1638 while True:
1639 partition = getter(self, size)
1640 if partition:
1641 yield partition
1642 else:
1643 break
1644
1645 def fetchall(self) -> Sequence[RowMapping]:
1646 """A synonym for the :meth:`_engine.MappingResult.all` method."""

Callers 1

mappingsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected