MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _copy

Method _copy

lib/sqlalchemy/sql/schema.py:2737–2805  ·  view source on GitHub ↗

Create a copy of this ``Column``, uninitialized. This is used in :meth:`_schema.Table.to_metadata` and by the ORM.

(self, **kw: Any)

Source from the content-addressed store, hash-verified

2735 return self._copy(**kw)
2736
2737 def _copy(self, **kw: Any) -> Column[Any]:
2738 """Create a copy of this ``Column``, uninitialized.
2739
2740 This is used in :meth:`_schema.Table.to_metadata` and by the ORM.
2741
2742 """
2743
2744 # Constraint objects plus non-constraint-bound ForeignKey objects
2745 args: List[SchemaItem] = [
2746 c._copy(**kw) for c in self.constraints if not c._type_bound
2747 ] + [c._copy(**kw) for c in self.foreign_keys if not c.constraint]
2748
2749 # ticket #5276
2750 column_kwargs = {}
2751 for dialect_name in self.dialect_options:
2752 dialect_options = self.dialect_options[dialect_name]._non_defaults
2753 for (
2754 dialect_option_key,
2755 dialect_option_value,
2756 ) in dialect_options.items():
2757 column_kwargs[dialect_name + "_" + dialect_option_key] = (
2758 dialect_option_value
2759 )
2760
2761 server_default = self.server_default
2762 server_onupdate = self.server_onupdate
2763 if isinstance(server_default, (Computed, Identity)):
2764 # TODO: likely should be copied in all cases
2765 # TODO: if a Sequence, we would need to transfer the Sequence
2766 # .metadata as well
2767 args.append(server_default._copy(**kw))
2768 server_default = server_onupdate = None
2769
2770 type_ = self.type
2771 if isinstance(type_, SchemaEventTarget):
2772 type_ = type_.copy(**kw)
2773
2774 # TODO: DefaultGenerator is not copied here! it's just used again
2775 # with _set_parent() pointing to the old column. see the new
2776 # use of _copy() in the new _merge() method
2777
2778 c = self._constructor(
2779 name=self.name,
2780 type_=type_,
2781 key=self.key,
2782 primary_key=self.primary_key,
2783 unique=self.unique,
2784 system=self.system,
2785 # quote=self.quote, # disabled 2013-08-27 (commit 031ef080)
2786 index=self.index,
2787 autoincrement=self.autoincrement,
2788 default=self.default,
2789 server_default=server_default,
2790 onupdate=self.onupdate,
2791 server_onupdate=server_onupdate,
2792 doc=self.doc,
2793 comment=self.comment,
2794 _omit_from_statements=self._omit_from_statements,

Calls 5

_schema_item_copyMethod · 0.80
itemsMethod · 0.45
appendMethod · 0.45
copyMethod · 0.45
_constructorMethod · 0.45