summaryrefslogtreecommitdiff
path: root/app/python/rcal/db.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-02-24 23:38:27 +0100
committeremkael <emkael@tlen.pl>2016-02-24 23:41:25 +0100
commit2173f7d7613b5158f4bb2f71a02df353c058c1ee (patch)
treeeac23e40bc497706b862b5d2ca01920c4b37ed92 /app/python/rcal/db.py
parent6e72eace43adc48f0b311c26d66d13315e25fe93 (diff)
* moving PHP app files to app/php and Python app files to app/python
Diffstat (limited to 'app/python/rcal/db.py')
-rw-r--r--app/python/rcal/db.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/app/python/rcal/db.py b/app/python/rcal/db.py
new file mode 100644
index 0000000..68d5b0d
--- /dev/null
+++ b/app/python/rcal/db.py
@@ -0,0 +1,34 @@
+import json
+from os import path
+
+import sqlalchemy.engine.url as url
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+
+
+class Session(object):
+
+ engine = None
+
+ def __init__(self):
+ config = json.load(
+ open(path.join(path.dirname(
+ path.realpath(__file__)), '../../..', 'conf', 'db.json')))
+ db_str = url.URL(
+ drivername=config['type'],
+ host=config['host'],
+ username=config['user'],
+ password=config['pass'],
+ database=config['name'],
+ query={'charset': config['cset']}
+ )
+ self.engine = create_engine(db_str, encoding=config['cset'])
+
+ def get_maker(self):
+ return sessionmaker(bind=self.engine)
+
+ @staticmethod
+ def create():
+ session = Session()
+ maker = session.get_maker()
+ return maker()