Plain column getter, stores collection of Column objects directly. Serializes to a :class:`._SerializableColumnGetterV2` which has more expensive __call__() performance and some rare caveats.
| 44 | |
| 45 | |
| 46 | class _PlainColumnGetter(Generic[_KT]): |
| 47 | """Plain column getter, stores collection of Column objects |
| 48 | directly. |
| 49 | |
| 50 | Serializes to a :class:`._SerializableColumnGetterV2` |
| 51 | which has more expensive __call__() performance |
| 52 | and some rare caveats. |
| 53 | |
| 54 | """ |
| 55 | |
| 56 | __slots__ = ("cols", "composite") |
| 57 | |
| 58 | def __init__(self, cols: Sequence[ColumnElement[_KT]]) -> None: |
| 59 | self.cols = cols |
| 60 | self.composite = len(cols) > 1 |
| 61 | |
| 62 | def __reduce__( |
| 63 | self, |
| 64 | ) -> Tuple[ |
| 65 | Type[_SerializableColumnGetterV2[_KT]], |
| 66 | Tuple[Sequence[Tuple[Optional[str], Optional[str]]]], |
| 67 | ]: |
| 68 | return _SerializableColumnGetterV2._reduce_from_cols(self.cols) |
| 69 | |
| 70 | def _cols(self, mapper: Mapper[_KT]) -> Sequence[ColumnElement[_KT]]: |
| 71 | return self.cols |
| 72 | |
| 73 | def __call__(self, value: _KT) -> MissingOr[Union[_KT, Tuple[_KT, ...]]]: |
| 74 | state = base.instance_state(value) |
| 75 | m = base._state_mapper(state) |
| 76 | |
| 77 | key: List[_KT] = [ |
| 78 | m._get_state_attr_by_column(state, state.dict, col) |
| 79 | for col in self._cols(m) |
| 80 | ] |
| 81 | if self.composite: |
| 82 | return tuple(key) |
| 83 | else: |
| 84 | obj = key[0] |
| 85 | if obj is None: |
| 86 | return Missing |
| 87 | else: |
| 88 | return obj |
| 89 | |
| 90 | |
| 91 | class _SerializableColumnGetterV2(_PlainColumnGetter[_KT]): |