[Checkins] SVN: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/ removed
stupid new 'model_provider' parameter,
Andreas Jung
andreas at andreas-jung.com
Mon Apr 23 10:08:30 EDT 2007
Log message for revision 74680:
removed stupid new 'model_provider' parameter,
we have the 'model' parameter for this!!!
Changed:
U z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt
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/test.py
-=-
Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt 2007-04-23 13:41:59 UTC (rev 74679)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt 2007-04-23 14:08:29 UTC (rev 74680)
@@ -1,11 +1,11 @@
0.1.9 (unreleased)
- - base.py: deprecated 'model' parameter
+ - base.py: the 'model' parameter can now also be a callable
+ returning an instance of model.Model
- - base.py: added 'model_provider' parameter which is
- an optional callable called with a BoundMetaData
- instance in order to auto-load tables (which requires
- BoundMetaData).
+ - base.py: calling a model provider or a method providing a
+ model with a BoundMetaData instance in order to allow
+ table auto-loading
0.1.8 (23.04.2007)
Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py 2007-04-23 13:41:59 UTC (rev 74679)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py 2007-04-23 14:08:29 UTC (rev 74680)
@@ -6,7 +6,6 @@
# and ZOPYX Ltd. & Co. KG, Tuebingen, Germany
##########################################################################
-import warnings
import threading
import sqlalchemy
@@ -28,14 +27,11 @@
implements(ISQLAlchemyWrapper)
- def __init__(self, dsn, model=None, model_provider=None, **kw):
+ def __init__(self, dsn, model=None, **kw):
""" 'dsn' - a RFC-1738-style connection string
'model' - optional instance of model.Model
- 'model_provider' - optional callable providing an instance
- of model.Model()
-
'kw' - optional keyword arguments passed to create_engine()
"""
@@ -53,37 +49,36 @@
self._engine.echo = self.echo
self._model = None
- if model is not None and model_provider is not None:
- raise ValueError("You can not specify both 'model' and 'model_provider' at the same time")
if model:
- warnings.warn("The 'model' parameter is deprecated. Use 'model_provider' instead", DeprecationWarning, stacklevel=1)
if isinstance(model, Model):
self._model = model
elif isinstance(model, basestring):
+
try:
util = getUtility(IModelProvider, model)
except ComponentLookupError:
raise ComponentLookupError("No named utility '%s' providing IModelProvider found" % model)
- self._model = util.getModel()
+ 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 "\
"an instance of z3c.sqlalchemy.model.Model.")
- if model_provider:
+ if not isinstance(self._model, Model):
+ raise TypeError('_model is not an instance of model.Model')
- if not callable(model_provider):
- raise ValueError('model_provider must be callable')
- self._model = model_provider(self.metadata)
-
# mappers must be initialized at last since we need to acces
# the 'model' from within the constructor of LazyMapperCollection
self._mappers = LazyMapperCollection(self)
Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/interfaces.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/interfaces.py 2007-04-23 13:41:59 UTC (rev 74679)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/interfaces.py 2007-04-23 14:08:29 UTC (rev 74680)
@@ -60,7 +60,7 @@
and the mapper classes.
"""
- def getModel():
+ def getModel(metadata=None):
""" The model is described as an ordered dictionary. The entries are
(tablename, some_dict) where 'some_dict' is a dictionary containing a
key 'table' referencing a Table() instance and an optional key
Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/test.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/test.py 2007-04-23 13:41:59 UTC (rev 74679)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/test.py 2007-04-23 14:08:29 UTC (rev 74680)
@@ -1,19 +1,52 @@
-from haufe.sqlalchemy import createSQLAlchemyWrapper, Model
+from sqlalchemy import *
+from z3c.sqlalchemy import createSQLAlchemyWrapper, Model
+from z3c.sqlalchemy.mapper import MappedClassBase
-class Format(object):
+dsn = 'postgres://postgres:postgres@cmsdb/Toolbox2Test'
+
+class HierarchyNode(MappedClassBase):
pass
-m = Model({'name' : 'format', 'autodetect_relations' : True, 'mapper_class' : Format},
- {'name' : 'medium', 'autodetect_relations' : True})
+# FIX THIS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+e = create_engine(dsn)
+metadata = BoundMetaData(e)
+# FIX THIS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+HierarchyTable = Table('hierarchy', metadata,
+ Column('parentid', Integer, ForeignKey('hierarchy.id')),
+ autoload=True)
-w = createSQLAlchemyWrapper('postgres://postgres:postgres@cmsdb/MedienDB', model=m)
-print w
-f = w.getMapper('format')
-m = w.getMapper('medium')
+mapper(HierarchyNode, HierarchyTable, properties={
+ 'children' : relation(
+ HierarchyNode,
+ primaryjoin=HierarchyTable.c.parentid==HierarchyTable.c.id,
+ cascade="all",
+ backref=backref("parent", remote_side=[HierarchyTable.c.id])
+ ),
+ 'parent' : relation(
+ HierarchyNode,
+ primaryjoin=HierarchyTable.c.parentid==HierarchyTable.c.id,
+ remote_side=[HierarchyTable.c.id],
+ uselist=False,
+ ),
+ }
+)
-session = w.session
-for row in session.query(f).select():
- print row.versionfiles
+m = Model()
+m.add('hierarchy', table=HierarchyTable, mapper_class=HierarchyNode)
+
+
+
+
+
+wrapper = createSQLAlchemyWrapper(dsn, model=m)
+session = wrapper.session
+
+
+H = wrapper.getMapper('hierarchy')
+
+print H
+rows = session.query(H).select_by(H.c.id==8)
+print rows[0].children
More information about the Checkins
mailing list