diff options
Diffstat (limited to 'portato/db/__init__.py')
-rw-r--r-- | portato/db/__init__.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/portato/db/__init__.py b/portato/db/__init__.py index 122940a..40bf9ee 100644 --- a/portato/db/__init__.py +++ b/portato/db/__init__.py @@ -12,14 +12,23 @@ from __future__ import absolute_import +from ..session import Session, SectionDict from ..constants import USE_SQL from ..helper import debug -if USE_SQL: - debug("Using SQLDatabase") - from .sql import SQLDatabase - Database = SQLDatabase -else: - debug("Using DictDatabase") - from .dict import DictDatabase - Database = DictDatabase +_SESSION = None + +def Database(): + global _SESSION + + if _SESSION is None: + _SESSION = Session("db.cfg", name = "DB") + + if USE_SQL: + debug("Using SQLDatabase") + from .sql import SQLDatabase + return SQLDatabase(SectionDict(_SESSION, "SQL")) + else: + debug("Using DictDatabase") + from .dict import DictDatabase + return DictDatabase(SectionDict(_SESSION, "dict")) |