From ecb3865615082301c2e5ab7f8e8a40bfbb99b05c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 Jan 2014 21:12:31 -0500 Subject: - The :paramref:`.Table.extend_existing` and :paramref:`.Table.autoload_replace` parameters are now available on the :meth:`.MetaData.reflect` method. - starting to use paramref and need newer paramlinks version. --- lib/sqlalchemy/sql/schema.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 6205ada34..97c160bf5 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -2894,7 +2894,9 @@ class MetaData(SchemaItem): """ return ddl.sort_tables(self.tables.values()) - def reflect(self, bind=None, schema=None, views=False, only=None): + def reflect(self, bind=None, schema=None, views=False, only=None, + extend_existing=False, + autoload_replace=True): """Load all available table definitions from the database. Automatically creates ``Table`` entries in this ``MetaData`` for any @@ -2929,6 +2931,17 @@ class MetaData(SchemaItem): with a table name and this ``MetaData`` instance as positional arguments and should return a true value for any table to reflect. + :param extend_existing: Passed along to each :class:`.Table` as + :paramref:`.Table.extend_existing`. + + .. versionadded:: 0.9.1 + + :param autoload_replace: Passed along to each :class:`.Table` as + :paramref:`.Table.autoload_replace`. + + .. versionadded:: 0.9.1 + + """ if bind is None: bind = _bind_or_error(self) @@ -2937,7 +2950,9 @@ class MetaData(SchemaItem): reflect_opts = { 'autoload': True, - 'autoload_with': conn + 'autoload_with': conn, + 'extend_existing': extend_existing, + 'autoload_replace': autoload_replace } if schema is None: @@ -2963,12 +2978,13 @@ class MetaData(SchemaItem): if only is None: load = [name for name, schname in - zip(available, available_w_schema) - if schname not in current] + zip(available, available_w_schema) + if extend_existing or schname not in current] elif util.callable(only): load = [name for name, schname in zip(available, available_w_schema) - if schname not in current and only(name, self)] + if (extend_existing or schname not in current) + and only(name, self)] else: missing = [name for name in only if name not in available] if missing: @@ -2977,7 +2993,8 @@ class MetaData(SchemaItem): 'Could not reflect: requested table(s) not available ' 'in %s%s: (%s)' % (bind.engine.url, s, ', '.join(missing))) - load = [name for name in only if name not in current] + load = [name for name in only if extend_existing or + name not in current] for name in load: Table(name, self, **reflect_opts) -- cgit v1.2.1 From 196f7ee6cc132aa0f31741af80fa5c0ba77efcf2 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 5 Jan 2014 14:11:12 -0500 Subject: - conjunctions like and_() and or_() can now accept generators as arguments. --- lib/sqlalchemy/sql/elements.py | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 56fca5dd8..c230802cc 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -1492,6 +1492,7 @@ class BooleanClauseList(ClauseList, ColumnElement): def _construct(cls, operator, continue_on, skip_on, *clauses, **kw): convert_clauses = [] + clauses = util.coerce_generator_arg(clauses) for clause in clauses: clause = _literal_as_text(clause) -- cgit v1.2.1 From 8c93a6c7718c2408688eb21a59e008a8dcca8999 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 5 Jan 2014 16:42:56 -0500 Subject: - fix some docstring stuff --- lib/sqlalchemy/sql/schema.py | 43 +++++++++++++++++++++++++++------------- lib/sqlalchemy/sql/selectable.py | 8 ++++++++ 2 files changed, 37 insertions(+), 14 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 97c160bf5..f8aaac12f 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -522,6 +522,14 @@ class Table(SchemaItem, TableClause): @property def key(self): + """Return the 'key' for this :class:`.Table`. + + This value is used as the dictionary key within the + :attr:`.MetaData.tables` collection. It is typically the same + as that of :attr:`.Table.name` for a table with no :attr:`.Table.schema` + set; otherwise it is typically of the form ``schemaname.tablename``. + + """ return _get_table_key(self.name, self.schema) def __repr__(self): @@ -2719,20 +2727,11 @@ class MetaData(SchemaItem): execution. The :class:`.Table` objects themselves are stored in the - ``metadata.tables`` dictionary. - - The ``bind`` property may be assigned to dynamically. A common pattern is - to start unbound and then bind later when an engine is available:: + :attr:`.MetaData.tables` dictionary. - metadata = MetaData() - # define tables - Table('mytable', metadata, ...) - # connect to an engine later, perhaps after loading a URL from a - # configuration file - metadata.bind = an_engine - - MetaData is a thread-safe object after tables have been explicitly defined - or loaded via reflection. + :class:`.MetaData` is a thread-safe object for read operations. Construction + of new tables within a single :class:`.MetaData` object, either explicitly + or via reflection, may not be completely thread-safe. .. seealso:: @@ -2788,6 +2787,20 @@ class MetaData(SchemaItem): "with reflect=True") self.reflect() + tables = None + """A dictionary of :class:`.Table` objects keyed to their name or "table key". + + The exact key is that determined by the :attr:`.Table.key` attribute; + for a table with no :attr:`.Table.schema` attribute, this is the same + as :attr:`.Table.name`. For a table with a schema, it is typically of the + form ``schemaname.tablename``. + + .. seealso:: + + :attr:`.MetaData.sorted_tables` + + """ + def __repr__(self): return 'MetaData(bind=%r)' % self.bind @@ -2889,7 +2902,9 @@ class MetaData(SchemaItem): .. seealso:: - :meth:`.Inspector.sorted_tables` + :attr:`.MetaData.tables` + + :meth:`.Inspector.get_table_names` """ return ddl.sort_tables(self.tables.values()) diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index ab8b6667c..887805aad 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -136,7 +136,15 @@ class FromClause(Selectable): __visit_name__ = 'fromclause' named_with_column = False _hide_froms = [] + schema = None + """Define the 'schema' attribute for this :class:`.FromClause`. + + This is typically ``None`` for most objects except that of :class:`.Table`, + where it is taken as the value of the :paramref:`.Table.schema` argument. + + """ + _memoized_property = util.group_expirable_memoized_property(["_columns"]) @util.dependencies("sqlalchemy.sql.functions") -- cgit v1.2.1