def __init__(self, name, map_column=None,
descriptor=None, comparator_factory=None,
- doc=None):
+ doc=None, info=None):
"""Denote an attribute name as a synonym to a mapped property,
in that the attribute will mirror the value and expression behavior
of another attribute.
conjunction with the ``descriptor`` argument in order to link a
user-defined descriptor as a "wrapper" for an existing column.
+ :param info: Optional data dictionary which will be populated into the
+ :attr:`.InspectionAttr.info` attribute of this object.
+
+ .. versionadded:: 1.0.0
+
:param comparator_factory: A subclass of :class:`.PropComparator`
that will provide custom comparison behavior at the SQL expression
level.
self.descriptor = descriptor
self.comparator_factory = comparator_factory
self.doc = doc or (descriptor and descriptor.__doc__) or None
+ if info:
+ self.info = info
util.set_creation_order(self)
class ComparableProperty(DescriptorProperty):
"""Instruments a Python property for use in query expressions."""
- def __init__(self, comparator_factory, descriptor=None, doc=None):
+ def __init__(
+ self, comparator_factory, descriptor=None, doc=None, info=None):
"""Provides a method of applying a :class:`.PropComparator`
to any Python descriptor attribute.
The like-named descriptor will be automatically retrieved from the
mapped class if left blank in a ``properties`` declaration.
+ :param info: Optional data dictionary which will be populated into the
+ :attr:`.InspectionAttr.info` attribute of this object.
+
+ .. versionadded:: 1.0.0
+
"""
self.descriptor = descriptor
self.comparator_factory = comparator_factory
self.doc = doc or (descriptor and descriptor.__doc__) or None
+ if info:
+ self.info = info
util.set_creation_order(self)
def _comparator_factory(self, mapper):
return []
def __repr__(self):
- return util.generic_repr(self)
+ return util.generic_repr(self, omit_kwarg=['info'])
@property
@util.deprecated('0.9', 'Use ``<obj>.name.quote``')
def __init__(self, column, _constraint=None, use_alter=False, name=None,
onupdate=None, ondelete=None, deferrable=None,
initially=None, link_to_name=False, match=None,
+ info=None,
**dialect_kw):
"""
Construct a column-level FOREIGN KEY.
DDL for this constraint. Typical values include SIMPLE, PARTIAL
and FULL.
+ :param info: Optional data dictionary which will be populated into the
+ :attr:`.SchemaItem.info` attribute of this object.
+
+ .. versionadded:: 1.0.0
+
:param \**dialect_kw: Additional keyword arguments are dialect
specific, and passed in the form ``<dialectname>_<argname>``. The
arguments are ultimately handled by a corresponding
self.initially = initially
self.link_to_name = link_to_name
self.match = match
+ if info:
+ self.info = info
self._unvalidated_dialect_kw = dialect_kw
def __repr__(self):
__visit_name__ = 'constraint'
def __init__(self, name=None, deferrable=None, initially=None,
- _create_rule=None,
+ _create_rule=None, info=None,
**dialect_kw):
"""Create a SQL constraint.
Optional string. If set, emit INITIALLY <value> when issuing DDL
for this constraint.
+ :param info: Optional data dictionary which will be populated into the
+ :attr:`.SchemaItem.info` attribute of this object.
+
+ .. versionadded:: 1.0.0
+
:param _create_rule:
a callable which is passed the DDLCompiler object during
compilation. Returns True or False to signal inline generation of
self.name = name
self.deferrable = deferrable
self.initially = initially
+ if info:
+ self.info = info
self._create_rule = _create_rule
util.set_creation_order(self)
self._validate_dialect_kwargs(dialect_kw)
"""
def __init__(self, sqltext, name=None, deferrable=None,
- initially=None, table=None, _create_rule=None,
+ initially=None, table=None, info=None, _create_rule=None,
_autoattach=True):
"""Construct a CHECK constraint.
Optional string. If set, emit INITIALLY <value> when issuing DDL
for this constraint.
+ :param info: Optional data dictionary which will be populated into the
+ :attr:`.SchemaItem.info` attribute of this object.
+
+ .. versionadded:: 1.0.0
+
"""
super(CheckConstraint, self).\
- __init__(name, deferrable, initially, _create_rule)
+ __init__(name, deferrable, initially, _create_rule, info=info)
self.sqltext = _literal_as_text(sqltext)
if table is not None:
self._set_parent_with_dispatch(table)
def __init__(self, columns, refcolumns, name=None, onupdate=None,
ondelete=None, deferrable=None, initially=None,
use_alter=False, link_to_name=False, match=None,
- table=None, **dialect_kw):
+ table=None, info=None, **dialect_kw):
"""Construct a composite-capable FOREIGN KEY.
:param columns: A sequence of local column names. The named columns
DDL for this constraint. Typical values include SIMPLE, PARTIAL
and FULL.
+ :param info: Optional data dictionary which will be populated into the
+ :attr:`.SchemaItem.info` attribute of this object.
+
+ .. versionadded:: 1.0.0
+
:param \**dialect_kw: Additional keyword arguments are dialect
specific, and passed in the form ``<dialectname>_<argname>``. See
the documentation regarding an individual dialect at
"""
super(ForeignKeyConstraint, self).\
- __init__(name, deferrable, initially, **dialect_kw)
+ __init__(name, deferrable, initially, info=info, **dialect_kw)
self.onupdate = onupdate
self.ondelete = ondelete
the index. Works in the same manner as that of
:paramref:`.Column.quote`.
+ :param info=None: Optional data dictionary which will be populated
+ into the :attr:`.SchemaItem.info` attribute of this object.
+
+ .. versionadded:: 1.0.0
+
:param \**kw: Additional keyword arguments not mentioned above are
dialect specific, and passed in the form
``<dialectname>_<argname>``. See the documentation regarding an
self.expressions = expressions
self.name = quoted_name(name, kw.pop("quote", None))
self.unique = kw.pop('unique', False)
+ if 'info' in kw:
+ self.info = kw.pop('info')
self._validate_dialect_kwargs(kw)
# will call _set_parent() if table-bound column
def __init__(self, bind=None, reflect=False, schema=None,
quote_schema=None,
- naming_convention=DEFAULT_NAMING_CONVENTION
+ naming_convention=DEFAULT_NAMING_CONVENTION,
+ info=None
):
"""Create a new MetaData object.
:class:`.Sequence`, and other objects which make usage of the
local ``schema`` name.
+ :param info: Optional data dictionary which will be populated into the
+ :attr:`.SchemaItem.info` attribute of this object.
+
+ .. versionadded:: 1.0.0
+
:param naming_convention: a dictionary referring to values which
will establish default naming conventions for :class:`.Constraint`
and :class:`.Index` objects, for those objects which are not given
self.tables = util.immutabledict()
self.schema = quoted_name(schema, quote_schema)
self.naming_convention = naming_convention
+ if info:
+ self.info = info
self._schemas = set()
self._sequences = {}
self._fk_memos = collections.defaultdict(list)
'mytable.myid = othertable.myid')
+class InfoTest(fixtures.TestBase):
+ def test_metadata_info(self):
+ m1 = MetaData()
+ eq_(m1.info, {})
+
+ m1 = MetaData(info={"foo": "bar"})
+ eq_(m1.info, {"foo": "bar"})
+
+ def test_foreignkey_constraint_info(self):
+ fkc = ForeignKeyConstraint(['a'], ['b'], name='bar')
+ eq_(fkc.info, {})
+
+ fkc = ForeignKeyConstraint(
+ ['a'], ['b'], name='bar', info={"foo": "bar"})
+ eq_(fkc.info, {"foo": "bar"})
+
+ def test_foreignkey_info(self):
+ fkc = ForeignKey('a')
+ eq_(fkc.info, {})
+
+ fkc = ForeignKey('a', info={"foo": "bar"})
+ eq_(fkc.info, {"foo": "bar"})
+
+ def test_primarykey_constraint_info(self):
+ pkc = PrimaryKeyConstraint('a', name='x')
+ eq_(pkc.info, {})
+
+ pkc = PrimaryKeyConstraint('a', name='x', info={'foo': 'bar'})
+ eq_(pkc.info, {'foo': 'bar'})
+
+ def test_unique_constraint_info(self):
+ uc = UniqueConstraint('a', name='x')
+ eq_(uc.info, {})
+
+ uc = UniqueConstraint('a', name='x', info={'foo': 'bar'})
+ eq_(uc.info, {'foo': 'bar'})
+
+ def test_check_constraint_info(self):
+ cc = CheckConstraint('foo=bar', name='x')
+ eq_(cc.info, {})
+
+ cc = CheckConstraint('foo=bar', name='x', info={'foo': 'bar'})
+ eq_(cc.info, {'foo': 'bar'})
+
+ def test_index_info(self):
+ ix = Index('x', 'a')
+ eq_(ix.info, {})
+
+ ix = Index('x', 'a', info={'foo': 'bar'})
+ eq_(ix.info, {'foo': 'bar'})
+
+ def test_column_info(self):
+ c = Column('x', Integer)
+ eq_(c.info, {})
+
+ c = Column('x', Integer, info={'foo': 'bar'})
+ eq_(c.info, {'foo': 'bar'})
+
+ def test_table_info(self):
+ t = Table('x', MetaData())
+ eq_(t.info, {})
+
+ t = Table('x', MetaData(), info={'foo': 'bar'})
+ eq_(t.info, {'foo': 'bar'})
+
class TableTest(fixtures.TestBase, AssertsCompiledSQL):
@testing.skip_if('mssql', 'different col format')