diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-10-14 21:58:04 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-10-14 21:58:04 +0000 |
| commit | 8340006dd7ed34cf32bbb7f856397d1c7f13d295 (patch) | |
| tree | 3429fe31b379b2ccc10e6653e33d4d6d23fd5ae4 /lib/sqlalchemy/sql.py | |
| parent | 5bb47440e03bb6ac0d3bd92eab4a6d69304ff556 (diff) | |
| download | sqlalchemy-8340006dd7ed34cf32bbb7f856397d1c7f13d295.tar.gz | |
- a fair amount of cleanup to the schema package, removal of ambiguous
methods, methods that are no longer needed. slightly more constrained
useage, greater emphasis on explicitness.
- table_iterator signature fixup, includes fix for [ticket:288]
- the "primary_key" attribute of Table and other selectables becomes
a setlike ColumnCollection object; is no longer ordered or numerically
indexed. a comparison clause between two pks that are derived from the
same underlying tables (i.e. such as two Alias objects) can be generated
via table1.primary_key==table2.primary_key
- append_item() methods removed from Table and Column; preferably
construct Table/Column/related objects inline, but if needed use
append_column(), append_foreign_key(), append_constraint(), etc.
- table.create() no longer returns the Table object, instead has no
return value. the usual case is that tables are created via metadata,
which is preferable since it will handle table dependencies.
- added UniqueConstraint (goes at Table level), CheckConstraint
(goes at Table or Column level) fixes [ticket:217]
- index=False/unique=True on Column now creates a UniqueConstraint,
index=True/unique=False creates a plain Index,
index=True/unique=True on Column creates a unique Index. 'index'
and 'unique' keyword arguments to column are now boolean only; for
explcit names and groupings of indexes or unique constraints, use the
UniqueConstraint/Index constructs explicitly.
- relationship of Metadata/Table/SchemaGenerator/Dropper has been
improved so that the schemavisitor receives the metadata object
for greater control over groupings of creates/drops.
- added "use_alter" argument to ForeignKey, ForeignKeyConstraint,
but it doesnt do anything yet. will utilize new generator/dropper
behavior to implement.
Diffstat (limited to 'lib/sqlalchemy/sql.py')
| -rw-r--r-- | lib/sqlalchemy/sql.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index c113edaa3..6f51ccbe9 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -658,6 +658,17 @@ class ColumnElement(Selectable, CompareMixin): else: return self +class ColumnCollection(util.OrderedProperties): + def add(self, column): + self[column.key] = column + def __eq__(self, other): + l = [] + for c in other: + for local in self: + if c.shares_lineage(local): + l.append(c==local) + return and_(*l) + class FromClause(Selectable): """represents an element that can be used within the FROM clause of a SELECT statement.""" def __init__(self, name=None): @@ -671,7 +682,7 @@ class FromClause(Selectable): visitor.visit_fromclause(self) def count(self, whereclause=None, **params): if len(self.primary_key): - col = self.primary_key[0] + col = list(self.primary_key)[0] else: col = list(self.columns)[0] return select([func.count(col).label('tbl_row_count')], whereclause, from_obj=[self], **params) @@ -735,8 +746,8 @@ class FromClause(Selectable): if hasattr(self, '_columns'): # TODO: put a mutex here ? this is a key place for threading probs return - self._columns = util.OrderedProperties() - self._primary_key = [] + self._columns = ColumnCollection() + self._primary_key = ColumnCollection() self._foreign_keys = util.Set() self._orig_cols = {} export = self._exportable_columns() @@ -1082,7 +1093,7 @@ class Join(FromClause): def _proxy_column(self, column): self._columns[column._label] = column if column.primary_key: - self._primary_key.append(column) + self._primary_key.add(column) for f in column.foreign_keys: self._foreign_keys.add(f) return column @@ -1257,9 +1268,9 @@ class TableClause(FromClause): def __init__(self, name, *columns): super(TableClause, self).__init__(name) self.name = self.fullname = name - self._columns = util.OrderedProperties() + self._columns = ColumnCollection() self._foreign_keys = util.Set() - self._primary_key = [] + self._primary_key = util.Set() for c in columns: self.append_column(c) self._oid_column = ColumnClause('oid', self, hidden=True) @@ -1282,16 +1293,6 @@ class TableClause(FromClause): return self._orig_cols original_columns = property(_orig_columns) - def _clear(self): - """clears all attributes on this TableClause so that new items can be added again""" - self.columns.clear() - self.foreign_keys[:] = [] - self.primary_key[:] = [] - try: - delattr(self, '_orig_cols') - except AttributeError: - pass - def accept_visitor(self, visitor): visitor.visit_table(self) def _exportable_columns(self): @@ -1305,7 +1306,7 @@ class TableClause(FromClause): data[self] = self def count(self, whereclause=None, **params): if len(self.primary_key): - col = self.primary_key[0] + col = list(self.primary_key)[0] else: col = list(self.columns)[0] return select([func.count(col).label('tbl_row_count')], whereclause, from_obj=[self], **params) |
