MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / format_constraint

Method format_constraint

lib/sqlalchemy/sql/compiler.py:7896–7919  ·  view source on GitHub ↗
(
        self, constraint: Union[Constraint, Index], _alembic_quote: bool = True
    )

Source from the content-addressed store, hash-verified

7894
7895 @util.preload_module("sqlalchemy.sql.naming")
7896 def format_constraint(
7897 self, constraint: Union[Constraint, Index], _alembic_quote: bool = True
7898 ) -> Optional[str]:
7899 naming = util.preloaded.sql_naming
7900
7901 if constraint.name is _NONE_NAME:
7902 name = naming._constraint_name_for_table(
7903 constraint, constraint.table
7904 )
7905
7906 if name is None:
7907 return None
7908 else:
7909 name = constraint.name
7910
7911 assert name is not None
7912 if constraint.__visit_name__ == "index":
7913 return self.truncate_and_render_index_name(
7914 name, _alembic_quote=_alembic_quote
7915 )
7916 else:
7917 return self.truncate_and_render_constraint_name(
7918 name, _alembic_quote=_alembic_quote
7919 )
7920
7921 def truncate_and_render_index_name(
7922 self, name: str, _alembic_quote: bool = True

Tested by 1

test_alembic_quoteMethod · 0.64