From b5998ad539035adb45dced86e3ef8365185cb18f Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 23 Feb 2016 13:52:48 +0100 Subject: * configure DB charset properly and change the way DB string is built --- conf/db.json | Bin 175 -> 167 bytes rcal/db.py | 13 ++++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/conf/db.json b/conf/db.json index 1c13879..936104f 100644 Binary files a/conf/db.json and b/conf/db.json differ diff --git a/rcal/db.py b/rcal/db.py index dffe98f..12fcd88 100644 --- a/rcal/db.py +++ b/rcal/db.py @@ -1,6 +1,7 @@ import json from os import path +import sqlalchemy.engine.url as url from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker @@ -13,9 +14,15 @@ class Session(object): config = json.load( open(path.join(path.dirname( path.realpath(__file__)), '..', 'conf', 'db.json'))) - db_str = "{0[type]}://{0[user]}:{0[pass]}@{0[host]}/{0[name]}".format( - config) - self.engine = create_engine(db_str) + 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) -- cgit v1.2.3