summaryrefslogtreecommitdiff
path: root/f1elo/db.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2014-10-29 14:14:20 +0100
committeremkael <emkael@tlen.pl>2014-10-29 14:14:20 +0100
commitb06c5a9f139e55e0f725d80b1cfdd7a76aa873f3 (patch)
treecfcc174ec65122af5e12ae0da34cc9b09ba07622 /f1elo/db.py
parent6713ff5db4d053a94d1e95ef36c7f2ff0c1a8208 (diff)
* foreign key support for SQLite
Diffstat (limited to 'f1elo/db.py')
-rw-r--r--f1elo/db.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/f1elo/db.py b/f1elo/db.py
index f4ed307..554a061 100644
--- a/f1elo/db.py
+++ b/f1elo/db.py
@@ -2,13 +2,16 @@ import json
from os import path
import __main__
-from sqlalchemy import create_engine
+from sqlalchemy import create_engine, event
from sqlalchemy.orm import sessionmaker
config = json.load(open(path.join(path.dirname(__main__.__file__), 'config', 'db.json')))
if config['engine'] == 'mysql':
engine = create_engine("mysql://{0[user]}:{0[pass]}@{0[host]}/{0[db]}?charset=utf8".format(config))
-else:
+elif config['engine'] == 'sqlite':
engine = create_engine("sqlite:///{0[file]}".format(config))
+ def fk_pragma(conn, record):
+ conn.execute('PRAGMA FOREIGN_KEYS=ON');
+ event.listen(engine, 'connect', fk_pragma)
Session = sessionmaker(bind=engine)