I have an application that will need to bind to several different databases with the same structure. The databases to be accessed are not known at import time, that will be determined later while the application is running. I want to use declarative and autoload the columns. Autoload needs a database connection available when a class is first compiled to do the database introspection, that is the part I can't figure out. Maybe a custom metaclass?
If this is already solved, can someone point me at the answer? I haven't found it yet. I want to do something like this: # declare a class used to manage connections to database instances class MyDatabase(object): ... magic happens here ... class User(..??..): __table_args__ = {'autoload':True} etc. def __init__(self, dbname): self.engine = create_engine(.. usual create engine stuff ..) self.metadata = MetaData(bind=engine) self.Session = sessionmaker(bind=engine) # probably have to do something here to create a self.User class???? def getsession(self): return self.Session() then the application code does things like: # something happens to determine a database to # connect to as dbname db = MyDatabase('dbname') session = db.getsession() users = session.query(db.User).all() etc. Now developers can connect to databases by name and have a ORM based programming interface. I have a solution that works well when I define columns in the class definitions, but I am looking for a solution that lets me use autoload. Regards, Mike --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---