Files
modoboa/lib/db.py
T
Antoine Nguyen fcab20b608 Important update of the plugin engine.
New plugin that allows the handling of an Amavisd-new SQL quarantine.

NB: a DB connections manager has been added inside the lib because
Django does not support multiple connections at the same time. The
main consequence is that we don't use an ORM and that we have to
rewrite a small wrapper that supports several DB (mysql, postgresql, etc.).
Adding a dependancy to an existing ORM module (like SQLalchemy) is
heavy, we don't want that for now.
2009-06-26 17:13:35 +02:00

23 lines
610 B
Python

# -*- coding: utf-8 -*-
"""
"""
connections = {}
def mysql_newconnection(host, dbname, login, password):
import MySQLdb
return MySQLdb.connect(host=host, db=dbname, user=login, passwd=password)
def getconnection(name):
if not name in connections.keys():
from django.conf import settings
cfg = settings.DB_CONNECTIONS[name]
if cfg["driver"] == "mysql":
conn = mysql_newconnection(cfg["host"], cfg["dbname"], cfg["login"],
cfg["password"])
connections[name] = conn
return connections[name]