I am trying to run multiple ORM's (sqlalchemy and ming) in TG2.2 so that I
can have easy access to two different databases.
I have both connections in development.ini (copied from two different
projects that work)
in project.model.__init__ I have:
# -*- coding: utf-8 -*-
> """The application's model objects"""
>
> import ming.orm
> from session import mainsession, DBSession
>
> from zope.sqlalchemy import ZopeTransactionExtension
> from sqlalchemy.orm import scoped_session, sessionmaker
> from sqlalchemy import MetaData
> from sqlalchemy.ext.declarative import declarative_base
>
> # Global session manager: DBSession() returns the Thread-local
> # session object appropriate for the current web request.
> maker = sessionmaker(autoflush=True, autocommit=False,
> extension=ZopeTransactionExtension())
> DBSession2 = scoped_session(maker)
>
> # Base class for all of our model classes: By default, the data model is
> # defined with SQLAlchemy's declarative extension, but if you need more
> # control, you can switch to the traditional method.
> DeclarativeBase2 = declarative_base()
>
> def init_model(engine):
> """Call me before using any of the tables or classes in the model."""
> mainsession.bind = engine
> ming.orm.Mapper.compile_all()
>
> for mapper in ming.orm.Mapper.all_mappers():
> mainsession.ensure_indexes(mapper.collection)
>
> metadata2 = DeclarativeBase2.metadata
> DBSession2.configure(bind=engine)
> metadata2.bind = engine
>
> # Import your model modules here.
> from project.model.auth import User, Group, Permission
>
However, the DBSession2 is still mapped to mongo:
>
> - File
>
> "/home/sjz/.virtualenvs/Project/lib/python2.7/site-packages/SQLAlchemy-0.8.1-py2.7-linux-x86_64.egg/sqlalchemy/schema.py",
>
> line *424*, in _autoload
>
> self, include_columns, exclude_columns
>
> [console ready]
> >>> selfTable('PIS_GENERAL2', MetaData(bind=<DataStore
> Database(MongoClient('localhost', 27017), u'project')>), schema=None)
> >>>
>
> - File
>
> "/home/sjz/.virtualenvs/Project/lib/python2.7/site-packages/pymongo-2.5.2-py2.7-linux-x86_64.egg/pymongo/collection.py",
>
> line *1418*, in __call__
>
> self.__name)
>
>
> TypeError: 'Collection' object is not callable. If you meant to call the
> 'run_callable' method on a 'Database' object it is failing because no such
> method exists.
>
> Any Ideas? How do I set it up to init two different engines and is it
possible?
>
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/groups/opt_out.