diff options
author | Miguel Gonzalez <migonzalvar@activitycentral.com> | 2013-08-06 19:25:32 (GMT) |
---|---|---|
committer | Miguel Gonzalez <migonzalvar@activitycentral.com> | 2013-08-06 19:25:32 (GMT) |
commit | 5dd4df4e51248d59ed5f92a4a86fe93cf76ccb1a (patch) | |
tree | ee5c6fef492389405617d77c678270444364c039 | |
parent | b4ac827a613652724733b04ba51fcd0ce761fc1a (diff) |
Extract engine creation to a private method
-rw-r--r-- | stats_consolidation/db.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/stats_consolidation/db.py b/stats_consolidation/db.py index e72ff40..32c98a2 100644 --- a/stats_consolidation/db.py +++ b/stats_consolidation/db.py @@ -88,16 +88,18 @@ class DB_Stats: def close (self): self.cnx.close() - def connect (self): + def _get_engine(self): database_url = 'mysql+mysqlconnector://{user}:{password}@localhost/{db_name}' engine = sa.create_engine(database_url.format( user=self.user, password=self.password, db_name=self.db_name) ) - self.cnx = Connection(engine) - return self.cnx + return engine + def connect (self): + self.cnx = Connection(self._get_engine()) + return self.cnx #========================================================================================================= # Q U E R I E S S A V E M E T H O D S |