]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
all create()/drop() calls have a keyword argument of "connectable".
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 9 Aug 2006 23:58:07 +0000 (23:58 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 9 Aug 2006 23:58:07 +0000 (23:58 +0000)
"engine" is deprecated. fixes [ticket:255]

CHANGES
doc/build/content/metadata.txt
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/schema.py

diff --git a/CHANGES b/CHANGES
index 16f10e81a82ab77896cdd10b5266bf39dd79cf9b..34344d4eeab09755b494aa9142dfd4684038c69f 100644 (file)
--- 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
index 6844fa12dbe0ec09d9a9ad6fcaf6ee4e3d890dfb..89f58b83ede7c89cb075ec32416dd3378614d581 100644 (file)
@@ -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, 
index ea678152e3ed9d7816f5040bb07c98a1bf09b509..cbf154e62fb174de3ffd395d5233ac26470b4ae0 100644 (file)
@@ -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()
index 002ff2d36c4fa1532da49d2fd26e69b8046b007d..8577b24e1e3f810277414b212c1266acd9c0bb50 100644 (file)
@@ -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