From: Paul Johnston Date: Tue, 6 Nov 2007 10:41:40 +0000 (+0000) Subject: Create a storage field for arbitrary info on tables/columns; ticket #573 X-Git-Tag: rel_0_4_1~52 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8f5d0cc4a2fe270e0ac84681f7824d1d9f2f9f8d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Create a storage field for arbitrary info on tables/columns; ticket #573 --- diff --git a/CHANGES b/CHANGES index 7c0c77296e..d337995f2f 100644 --- a/CHANGES +++ b/CHANGES @@ -36,6 +36,9 @@ CHANGES as well as to target result set columns originally bound to a table or selectable to an aliased, "corresponding" expression. The new rewrite features completely consistent and accurate behavior. + + - Added a field ("info") for storing arbitrary data on schema items + [ticket:573] - orm - eager loading with LIMIT/OFFSET applied no longer adds the primary diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index a7f24a211a..d05a8c13a3 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -71,10 +71,17 @@ class SchemaItem(object): else: m = self.metadata return m and m.bind or None - - bind = property(lambda s:s._get_bind()) + def info(self): + try: + return self._info + except AttributeError: + self._info = {} + return self._info + info = property(info) + + def _get_table_key(name, schema): if schema is None: return name @@ -156,6 +163,10 @@ class Table(SchemaItem, expression.TableClause): ``Table`` object. Defaults to ``None`` which indicates all columns should be reflected. + info + Defaults to {}: A space to store application specific data; + this must be a dictionary. + mustexist Defaults to False: indicates that this Table must already have been defined elsewhere in the application, else an @@ -199,6 +210,8 @@ class Table(SchemaItem, expression.TableClause): else: self.fullname = self.name self.owner = kwargs.pop('owner', None) + if kwargs.get('info'): + self._info = kwargs.pop('info') autoload = kwargs.pop('autoload', False) autoload_with = kwargs.pop('autoload_with', None) @@ -383,6 +396,10 @@ class Column(SchemaItem, expression._ColumnClause): specify indexes with explicit names or indexes that contain multiple columns, use the ``Index`` construct instead. + info + Defaults to {}: A space to store application specific data; + this must be a dictionary. + unique Defaults to False: indicates that this column contains a unique constraint, or if `index` is True as well, @@ -430,6 +447,8 @@ class Column(SchemaItem, expression._ColumnClause): self.autoincrement = kwargs.pop('autoincrement', True) self.constraints = util.Set() self._foreign_keys = util.OrderedSet() + if kwargs.get('info'): + self._info = kwargs.pop('info') if kwargs: raise exceptions.ArgumentError("Unknown arguments passed to Column: " + repr(kwargs.keys()))