This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
curunir/modules/pgsql.py

31 lines
779 B
Python
Raw Permalink Normal View History

2011-09-05 22:40:46 +02:00
from . import ModuleBase
2012-12-29 02:21:47 +01:00
import psycopg2
2011-09-05 22:40:46 +02:00
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
2012-12-29 02:21:47 +01:00
self.db = psycopg2.connect(host = self.conf['host'], user = self.conf['user'], password = self.conf['passwd'], database = self.conf['db'])
2011-09-05 22:40:46 +02:00
def cursor(self):
try:
return self.db.cursor()
2012-12-29 02:21:47 +01:00
except psycopg2.OperationalError:
2011-09-05 22:40:46 +02:00
self._connect()
return self.db.cursor()
def commit(self):
self.db.commit()