Commits

Sylvain Hellegouarch  committed 58ac04f

passing connection strings as argument

  • Participants
  • Parent commits 75e82c6

Comments (0)

Files changed (2)

File web/database/sql_alchemy/__init__.py

 if __name__ == '__main__':
     # Register the SQLAlchemy plugin
     from saplugin import SAEnginePlugin
-    SAEnginePlugin(cherrypy.engine).subscribe()
+    SAEnginePlugin(cherrypy.engine, 'sqlite:///my.db').subscribe()
 
     # Register the SQLAlchemy tool
     from satool import SATool

File web/database/sql_alchemy/saplugin.py

 __all__ = ['SAEnginePlugin']
         
 class SAEnginePlugin(plugins.SimplePlugin):
-    def __init__(self, bus):
+    def __init__(self, bus, connection_string=None):
         """
         The plugin is registered to the CherryPy engine and therefore
         is part of the bus (the engine *is* a bus) registery.
         """
         plugins.SimplePlugin.__init__(self, bus)
         self.sa_engine = None
+        self.connection_string = connection_string
         self.session = scoped_session(sessionmaker(autoflush=True,
                                                    autocommit=False))
  
     def start(self):
         self.bus.log('Starting up DB access')
-        self.sa_engine = create_engine('sqlite:///my.db', echo=False)
+        self.sa_engine = create_engine(self.connection_string, echo=False)
         self.bus.subscribe("bind-session", self.bind)
         self.bus.subscribe("commit-session", self.commit)