From: Mike Bayer Date: Wed, 9 Aug 2006 23:58:07 +0000 (+0000) Subject: all create()/drop() calls have a keyword argument of "connectable". X-Git-Tag: rel_0_2_7~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dde6a5aac085c86d4905c2514e7d0ab8f8b290d0;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git all create()/drop() calls have a keyword argument of "connectable". "engine" is deprecated. fixes [ticket:255] --- diff --git a/CHANGES b/CHANGES index 16f10e81a8..34344d4eea 100644 --- a/CHANGES +++ b/CHANGES @@ -25,7 +25,9 @@ for sqlite applications that dispose of threads en masse) - fixed small pickle bug(s) with lazy loaders [ticket:265] [ticket:267] - fixed possible error in mysql reflection where certain versions return an array instead of string for SHOW CREATE TABLE call -- fix to lazy loads when mapping to joins +- fix to lazy loads when mapping to joins [changeset:1770] +- all create()/drop() calls have a keyword argument of "connectable". +"engine" is deprecated. 0.2.6 - big overhaul to schema to allow truly composite primary and foreign diff --git a/doc/build/content/metadata.txt b/doc/build/content/metadata.txt index 6844fa12db..89f58b83ed 100644 --- a/doc/build/content/metadata.txt +++ b/doc/build/content/metadata.txt @@ -255,14 +255,14 @@ Creating and dropping individual tables can be done via the `create()` and `drop `drop()` method: {python} - {sql}employees.drop(engine=e) + {sql}employees.drop(connectable=e) DROP TABLE employees {} The `create()` and `drop()` methods also support an optional keyword argument `checkfirst` which will issue the database's appropriate pragma statements to check if the table exists before creating or dropping: {python} - employees.create(engine=e, checkfirst=True) + employees.create(connectable=e, checkfirst=True) employees.drop(checkfirst=False) Entire groups of Tables can be created and dropped directly from the `MetaData` object with `create_all()` and `drop_all()`. These methods always check for the existence of each table before creating or dropping. Each method takes an optional `engine` keyword argument which can reference an `Engine` or a `Connection`. If no engine is specified, the underlying bound `Engine`, if any, is used: @@ -286,7 +286,7 @@ Entire groups of Tables can be created and dropped directly from the `MetaData` Column('pref_value', String(100)) ) - {sql}metadata.create_all(engine=engine) + {sql}metadata.create_all(connectable=engine) PRAGMA table_info(users){} CREATE TABLE users( user_id INTEGER NOT NULL PRIMARY KEY, diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index ea678152e3..cbf154e62f 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -305,7 +305,7 @@ class Connection(Connectable): def default_schema_name(self): return self.__engine.dialect.get_default_schema_name(self) def run_callable(self, callable_): - callable_(self) + return callable_(self) def _execute_raw(self, statement, parameters=None, cursor=None, echo=None, context=None, **kwargs): if cursor is None: cursor = self.connection.cursor() diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 002ff2d36c..8577b24e1e 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -717,15 +717,15 @@ class Index(SchemaItem): % (self.name, column)) self.columns.append(column) - def create(self, engine=None): - if engine is not None: - engine.create(self) + def create(self, connectable=None): + if connectable is not None: + connectable.create(self) else: self.engine.create(self) return self - def drop(self, engine=None): - if engine is not None: - engine.drop(self) + def drop(self, connectable=None): + if connectable is not None: + connectable.drop(self) else: self.engine.drop(self) def accept_schema_visitor(self, visitor): @@ -751,12 +751,26 @@ class MetaData(SchemaItem): def table_iterator(self, reverse=True): return self._sort_tables(self.tables.values(), reverse=reverse) - def create_all(self, engine=None, tables=None): + def create_all(self, connectable=None, tables=None, engine=None): + """create all tables stored in this metadata. + + This will conditionally create tables depending on if they do not yet + exist in the database. + + connectable - a Connectable used to access the database; or use the engine + bound to this MetaData. + + tables - optional list of tables to create + + engine - deprecated argument.""" if not tables: tables = self.tables.values() - if engine is None and self.is_bound(): - engine = self.engine + if connectable is None: + connectable = engine + + if connectable is None and self.is_bound(): + connectable = self.engine def do(conn): e = conn.engine @@ -765,14 +779,28 @@ class MetaData(SchemaItem): if e.dialect.has_table(conn, table.name): continue conn.create(table) - engine.run_callable(do) + connectable.run_callable(do) + + def drop_all(self, connectable=None, tables=None, engine=None): + """drop all tables stored in this metadata. + + This will conditionally drop tables depending on if they currently + exist in the database. + + connectable - a Connectable used to access the database; or use the engine + bound to this MetaData. - def drop_all(self, engine=None, tables=None): + tables - optional list of tables to drop + + engine - deprecated argument.""" if not tables: tables = self.tables.values() - if engine is None and self.is_bound(): - engine = self.engine + if connectable is None: + connectable = engine + + if connectable is None and self.is_bound(): + connectable = self.engine def do(conn): e = conn.engine @@ -780,7 +808,7 @@ class MetaData(SchemaItem): for table in ts: if e.dialect.has_table(conn, table.name): conn.drop(table) - engine.run_callable(do) + connectable.run_callable(do) def _sort_tables(self, tables, reverse=False): import sqlalchemy.sql_util