MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / add

Method add

lib/sqlalchemy/sql/base.py:2138–2175  ·  view source on GitHub ↗

Add a column to this :class:`_sql.WriteableColumnCollection`. .. note:: This method is **not normally used by user-facing code**, as the :class:`_sql.WriteableColumnCollection` is usually part of an existing object such as a :class:`_schema.Table`. To ad

(
        self,
        column: ColumnElement[Any],
        key: Optional[_COLKEY] = None,
    )

Source from the content-addressed store, hash-verified

2136 )
2137
2138 def add(
2139 self,
2140 column: ColumnElement[Any],
2141 key: Optional[_COLKEY] = None,
2142 ) -> None:
2143 """Add a column to this :class:`_sql.WriteableColumnCollection`.
2144
2145 .. note::
2146
2147 This method is **not normally used by user-facing code**, as the
2148 :class:`_sql.WriteableColumnCollection` is usually part of an
2149 existing object such as a :class:`_schema.Table`. To add a
2150 :class:`_schema.Column` to an existing :class:`_schema.Table`
2151 object, use the :meth:`_schema.Table.append_column` method.
2152
2153 """
2154 colkey: _COLKEY
2155
2156 if key is None:
2157 colkey = column.key # type: ignore
2158 else:
2159 colkey = key
2160
2161 l = len(self._collection)
2162
2163 # don't really know how this part is supposed to work w/ the
2164 # covariant thing
2165
2166 _column = cast(_COL_co, column)
2167
2168 self._collection.append(
2169 (colkey, _column, _ColumnMetrics(self, _column))
2170 )
2171 self._colset.add(_column._deannotate())
2172
2173 self._index[l] = (colkey, _column)
2174 if colkey not in self._index:
2175 self._index[colkey] = (colkey, _column)
2176
2177 def _as_readonly(self) -> ReadOnlyColumnCollection[_COLKEY, _COL_co]:
2178 return ReadOnlyColumnCollection(self)

Callers 1

test_dupes_addMethod · 0.95

Calls 5

_ColumnMetricsClass · 0.85
castFunction · 0.70
appendMethod · 0.45
addMethod · 0.45
_deannotateMethod · 0.45

Tested by 1

test_dupes_addMethod · 0.76