diff options
author | emkael <emkael@tlen.pl> | 2016-02-24 23:38:27 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-02-24 23:41:25 +0100 |
commit | 2173f7d7613b5158f4bb2f71a02df353c058c1ee (patch) | |
tree | eac23e40bc497706b862b5d2ca01920c4b37ed92 /app/python/rcal/db.py | |
parent | 6e72eace43adc48f0b311c26d66d13315e25fe93 (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.py | 34 |
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() |