Hi,
I have a question that I can't find a satisfactory answer to. Apologies in
advance if it's more of a Python question, but it's possible that there is a SA
solution.
I have a project that defines a database connection and classes based on
database tables. A script that uses these classes would start with:
import project.DatabaseConnection as db # create_engine() and metadata defined
here
import project.ModelClasses
In ModelClasses, I define all of the table classes using:
Base = declarative_base(bind=db.engine)
class Table1(Base):
__tablename__ = 'table1'
__table_args__ = {'autoload' : True} # requires metadata to work
This is fine. I have a second project that also defines a different set of
tables that I want to use, so the main script would then:
import project2.ModelClasses # a different set of tables
If it's not clear how the "db" parameter (the database connection) was defined
in ModelClasses, well, that's my problem. I can't pass a parameter to an import
statement of course. The DatabaseConnection class defines the engine and
metadata, and now I need to use these objects to generate my base class. How
can I pass this object around? Should I be using a different model?
The "python way" seems to be to create a "config" class, but
project2.ModelClasses won't know anything about it if it's defined in the first
project. As to the reason why there are two separate projects, consider the
case where one set of tables is one logical group, and the second is a
replicated copy from another server. I can't merge all of these projects since
they really are independent "units", but sometimes I will link them (as above).
Any advice would be greatly appreciated!
Cheers,
Demitri
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.