Customizable db path in server

This commit is contained in:
Lucas Verney 2018-06-27 15:48:17 +02:00
parent e65be07fc1
commit b097bc2d2a
2 changed files with 7 additions and 1 deletions

View File

@ -59,6 +59,9 @@ adapt its behavior:
* `HOST=` to specify the host to listen to (defaults to `127.0.0.1` which * `HOST=` to specify the host to listen to (defaults to `127.0.0.1` which
means `localhost` only). means `localhost` only).
* `PORT=` to specify the port to listen on (defaults to `8081`). * `PORT=` to specify the port to listen on (defaults to `8081`).
* `DATABASE=` to specify a [database URL](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#db-url) to connect to (defaults to
`sqlite:///reports.db` which means a SQLite database named `reports.db` in
the current working directory).
### Serving ### Serving

View File

@ -3,11 +3,14 @@
""" """
Models and database definition Models and database definition
""" """
import os
import arrow import arrow
import peewee import peewee
from playhouse.db_url import connect
from playhouse.shortcuts import model_to_dict from playhouse.shortcuts import model_to_dict
db = peewee.SqliteDatabase('reports.db') db = connect(os.environ.get('DATABASE', 'sqlite:///reports.db'))
class BaseModel(peewee.Model): class BaseModel(peewee.Model):