Database: allow mysql, config in ini file
Also check for ini file existence at startup
This commit is contained in:
17
models.py
17
models.py
@@ -1,11 +1,24 @@
|
||||
from config import conf
|
||||
from peewee import SqliteDatabase
|
||||
from peewee import Model
|
||||
from peewee import AutoField, DateField, IntegerField
|
||||
|
||||
from peewee import IntegrityError
|
||||
|
||||
# SQLite database
|
||||
db = SqliteDatabase("fioul.db")
|
||||
backend = conf["db"].get("backend", None)
|
||||
if backend == "sqlite":
|
||||
# SQLite database
|
||||
db = SqliteDatabase(conf["sqlite"].get("filename", "sqlite.db"))
|
||||
elif backend == "mysql":
|
||||
db = MySQLDatabase(
|
||||
conf["mysql"].get("database"),
|
||||
user=conf["mysql"].get("user"),
|
||||
password=conf["mysql"].get("password"),
|
||||
host=conf["mysql"].get("host", "localhost"),
|
||||
port=conf["mysql"].getint("port", 3306),
|
||||
)
|
||||
else:
|
||||
db = None
|
||||
|
||||
|
||||
class BaseModel(Model):
|
||||
|
||||
Reference in New Issue
Block a user