[Checkins] SVN: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/ polishing

Andreas Jung andreas at andreas-jung.com
Sat May 5 02:44:23 EDT 2007


Log message for revision 75484:
  polishing
  

Changed:
  U   z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py
  U   z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/interfaces.py
  U   z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/model.py
  U   z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/tests/testSQLAlchemy.py
  U   z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/util.py

-=-
Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py	2007-05-05 06:33:49 UTC (rev 75483)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py	2007-05-05 06:44:23 UTC (rev 75484)
@@ -81,14 +81,11 @@
                 except ComponentLookupError:
                     raise ComponentLookupError("No named utility '%s' providing IModelProvider found" % model)
 
-
                 self._model = util.getModel(self.metadata)
 
             elif callable(model):                        
-
                 self._model = model(self.metadata)
 
-
             else:
                 raise ValueError("The 'model' parameter passed to constructor must either be "\
                                  "the name of a named utility implementing IModelProvider or "\

Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/interfaces.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/interfaces.py	2007-05-05 06:33:49 UTC (rev 75483)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/interfaces.py	2007-05-05 06:44:23 UTC (rev 75484)
@@ -70,3 +70,31 @@
             (otherwise a default mapper class will be autogenerated).
         """
 
+
+class IModel(Interface):
+    """ A model represents a configuration hint for SQLAlchemy wrapper instances
+        in order to deliver mappers for a given name.
+    """
+
+    def add(name, table=None, mapper_class=None, relations=None, autodetect_relations=False, table_name=None):
+        """ 'name'  -- name of table (no schema support so far!)
+
+            'table' -- a sqlalchemy.Table instance (None, for autoloading)
+
+            'mapper_class' -- an optional class to be used as mapper class for 'table'
+
+            'relations' -- an optional list of table names referencing 'table'. This is used 
+            for auto-constructing the relation properties of the mapper class.
+
+            'autodetect_relations' -- try to autodetect the relationships between tables
+            and auto-construct the relation properties of the mapper if
+            'relations' is omitted (set to None)
+
+            'table_name' -- optional full name of a table (e.g. 'someschema.sometable') if
+            you want to use 'name' as alias for the table.
+        """
+
+
+    def items():
+        """ return items in insertion order """
+

Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/model.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/model.py	2007-05-05 06:33:49 UTC (rev 75483)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/model.py	2007-05-05 06:44:23 UTC (rev 75484)
@@ -11,10 +11,11 @@
 Optional Model support 
 """
 
-
 import sqlalchemy
+from zope.interface import implements
 
 from mapper import MappedClassBase
+from interfaces import IModel
 
 __all__ = ('Model',)
 
@@ -25,6 +26,8 @@
         generation.
     """        
 
+    implements(IModel)
+
     def __init__(self, *args):
         """ The constructor can be called with a series of dict. Each dict
             represents a single table and its data (see add() method).

Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/tests/testSQLAlchemy.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/tests/testSQLAlchemy.py	2007-05-05 06:33:49 UTC (rev 75483)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/tests/testSQLAlchemy.py	2007-05-05 06:44:23 UTC (rev 75484)
@@ -18,7 +18,7 @@
 
 from zope.interface.verify import verifyClass
 
-from z3c.sqlalchemy.interfaces import ISQLAlchemyWrapper
+from z3c.sqlalchemy.interfaces import ISQLAlchemyWrapper, IModel
 from z3c.sqlalchemy.postgres import PythonPostgresWrapper,  ZopePostgresWrapper
 from z3c.sqlalchemy.base import BaseWrapper
 from z3c.sqlalchemy.mapper import MappedClassBase
@@ -65,7 +65,10 @@
     def testIFaceZopePostgres(self):
         verifyClass(ISQLAlchemyWrapper , ZopePostgresWrapper)
 
+    def testIModel(self):
+        verifyClass(IModel, Model)
 
+
     def testSimplePopulation(self):
         db = createSAWrapper('sqlite:///test')
         # obtain mapper for table 'user'

Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/util.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/util.py	2007-05-05 06:33:49 UTC (rev 75483)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/util.py	2007-05-05 06:44:23 UTC (rev 75484)
@@ -31,8 +31,16 @@
 def createSAWrapper(dsn, model=None, forZope=False, name=None, **kw):
     """ Convenience method to generate a wrapper for a DSN and a model.
         This method hides all database related magic from the user. 
-        Set 'forZope' to True to obtain a Zope-aware wrapper.
 
+        'dsn' - something like 'postgres://user:password@host/dbname'
+
+        'model' - None or  an instance of model.Model or a string representing
+        a named utility implementing IModelProvider or a method/callable returning an
+        instance of model.Model.
+
+        'forZope' - set this to True in order to obtain a Zope-transaction-aware
+        wrapper.
+
         'name' can be set to register the wrapper automatically  in order
         to avoid a dedicated registerSAWrapper() call.
     """



More information about the Checkins mailing list