diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-09-05 22:40:46 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-09-05 22:40:46 +0200 |
commit | a52e07d9047b0f41c16e51e083cc8639eaa88328 (patch) | |
tree | 12ad67511c03b639486d7d7f1eb73f72e1433978 /modules/pgsql.py | |
parent | aba29f23e65e61be194477df1e25fd355ca4dd65 (diff) | |
download | curunir-a52e07d9047b0f41c16e51e083cc8639eaa88328.tar curunir-a52e07d9047b0f41c16e51e083cc8639eaa88328.zip |
Changed log backend to PostgreSQL
Diffstat (limited to 'modules/pgsql.py')
-rw-r--r-- | modules/pgsql.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/pgsql.py b/modules/pgsql.py new file mode 100644 index 0000000..24cec76 --- /dev/null +++ b/modules/pgsql.py @@ -0,0 +1,30 @@ +from . import ModuleBase +from pyPgSQL import PgSQL + +class Module(ModuleBase): + def __init__(self, manager): + ModuleBase.__init__(self, manager) + + self.conf = manager.config['pgsql'] + + self.db = False + self._connect() + + def _connect(self): + if self.db: + try: + self.db.close() + except: + pass + + self.db = PgSQL.connect(host = self.conf['host'], user = self.conf['user'], password = self.conf['passwd'], database = self.conf['db'], client_encoding = 'utf8', unicode_results = 1) + + def cursor(self): + try: + return self.db.cursor() + except PgSQL.OperationalError: + self._connect() + return self.db.cursor() + + def commit(self): + self.db.commit() |