13 lines
458 B
Python
13 lines
458 B
Python
from flask import g, current_app
|
|
from .database.sqlite import SQLite
|
|
from pathlib import Path
|
|
|
|
def get_db():
|
|
db = getattr(g, "_database", None)
|
|
|
|
if db is None:
|
|
if str(current_app.config["config"]["database"]["type"]).casefold() == "SQLite".casefold():
|
|
database = Path(current_app.config['CONFIG_DIRECTORY']) / current_app.config['config']['database']['name']
|
|
db = g._database = SQLite(str(database))
|
|
|
|
return db |