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

Class conv

lib/sqlalchemy/sql/elements.py:5474–5522  ·  view source on GitHub ↗

Mark a string indicating that a name has already been converted by a naming convention. This is a string subclass that indicates a name that should not be subject to any further naming conventions. E.g. when we create a :class:`.Constraint` using a naming convention as follows:

Source from the content-addressed store, hash-verified

5472
5473
5474class conv(_truncated_label):
5475 """Mark a string indicating that a name has already been converted
5476 by a naming convention.
5477
5478 This is a string subclass that indicates a name that should not be
5479 subject to any further naming conventions.
5480
5481 E.g. when we create a :class:`.Constraint` using a naming convention
5482 as follows::
5483
5484 m = MetaData(
5485 naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
5486 )
5487 t = Table(
5488 "t", m, Column("x", Integer), CheckConstraint("x > 5", name="x5")
5489 )
5490
5491 The name of the above constraint will be rendered as ``"ck_t_x5"``.
5492 That is, the existing name ``x5`` is used in the naming convention as the
5493 ``constraint_name`` token.
5494
5495 In some situations, such as in migration scripts, we may be rendering
5496 the above :class:`.CheckConstraint` with a name that's already been
5497 converted. In order to make sure the name isn't double-modified, the
5498 new name is applied using the :func:`_schema.conv` marker. We can
5499 use this explicitly as follows::
5500
5501
5502 m = MetaData(
5503 naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
5504 )
5505 t = Table(
5506 "t",
5507 m,
5508 Column("x", Integer),
5509 CheckConstraint("x > 5", name=conv("ck_t_x5")),
5510 )
5511
5512 Where above, the :func:`_schema.conv` marker indicates that the constraint
5513 name here is final, and the name will render as ``"ck_t_x5"`` and not
5514 ``"ck_t_ck_t_x5"``
5515
5516 .. seealso::
5517
5518 :ref:`constraint_naming_conventions`
5519
5520 """
5521
5522 __slots__ = ()
5523
5524
5525# for backwards compatibility in case

Callers 3

selected_columnsMethod · 0.85
wrap_legFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected