From 07aedcdea97c01c5f1a1f3bc8d9f60a8516b42bf Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 17 Oct 2014 17:09:35 +0200 Subject: * SQLite support + config examples --- .gitignore | 1 + config/.gitignore | 1 + config/db.json | 6 ------ config/db.json.MYSQL-EXAMPLE | 7 +++++++ config/db.json.SQLITE-EXAMPLE | 4 ++++ f1elo/db.py | 5 ++++- 6 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 config/.gitignore delete mode 100644 config/db.json create mode 100644 config/db.json.MYSQL-EXAMPLE create mode 100644 config/db.json.SQLITE-EXAMPLE diff --git a/.gitignore b/.gitignore index 0d20b64..c6b032d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.pyc +elo.db diff --git a/config/.gitignore b/config/.gitignore new file mode 100644 index 0000000..58bd488 --- /dev/null +++ b/config/.gitignore @@ -0,0 +1 @@ +db.json diff --git a/config/db.json b/config/db.json deleted file mode 100644 index e283966..0000000 --- a/config/db.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "user": "USER", - "pass": "PASS", - "db": "DB", - "host": "HOST" -} diff --git a/config/db.json.MYSQL-EXAMPLE b/config/db.json.MYSQL-EXAMPLE new file mode 100644 index 0000000..15387cd --- /dev/null +++ b/config/db.json.MYSQL-EXAMPLE @@ -0,0 +1,7 @@ +{ + "engine": "mysql", + "user": "USER", + "pass": "PASS", + "db": "DATABASE", + "host": "HOST" +} diff --git a/config/db.json.SQLITE-EXAMPLE b/config/db.json.SQLITE-EXAMPLE new file mode 100644 index 0000000..67d58b0 --- /dev/null +++ b/config/db.json.SQLITE-EXAMPLE @@ -0,0 +1,4 @@ +{ + "engine": "sqlite", + "file": "elo.db" +} diff --git a/f1elo/db.py b/f1elo/db.py index cd7c4ac..8ecb0ac 100644 --- a/f1elo/db.py +++ b/f1elo/db.py @@ -7,7 +7,10 @@ from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker config = json.load(open(path.join(path.dirname(__main__.__file__), 'config', 'db.json'))) -engine = create_engine("mysql://{0[user]}:{0[pass]}@{0[host]}/{0[db]}?charset=utf8".format(config)) +if config['engine'] == 'mysql': + engine = create_engine("mysql://{0[user]}:{0[pass]}@{0[host]}/{0[db]}?charset=utf8".format(config)) +else: + engine = create_engine("sqlite:///{0[file]}".format(config)) Session = sessionmaker(bind=engine) def find_driver(name, country, session): -- cgit v1.2.3