summaryrefslogtreecommitdiff
path: root/src/home/database/sqlite.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-05-31 09:22:00 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-06-10 02:07:23 +0300
commitf29e139cbb7e4a4d539cba6e894ef4a6acd312d6 (patch)
tree6246f126325c5c36fb573134a05f2771cd747966 /src/home/database/sqlite.py
parent3e3753d726f8a02d98368f20f77dd9fa739e3d80 (diff)
WIP: big refactoring
Diffstat (limited to 'src/home/database/sqlite.py')
-rw-r--r--src/home/database/sqlite.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/home/database/sqlite.py b/src/home/database/sqlite.py
index bfba929..8c6145c 100644
--- a/src/home/database/sqlite.py
+++ b/src/home/database/sqlite.py
@@ -5,24 +5,27 @@ import logging
from ..config import config, is_development_mode
-def _get_database_path(name: str, dbname: str) -> str:
- return os.path.join(os.environ['HOME'], '.config', name, f'{dbname}.db')
+def _get_database_path(name: str) -> str:
+ return os.path.join(
+ os.environ['HOME'],
+ '.config',
+ 'homekit',
+ 'data',
+ f'{name}.db')
class SQLiteBase:
SCHEMA = 1
- def __init__(self, name=None, dbname='bot', check_same_thread=False):
- db_path = config.get('db_path', default=None)
- if db_path is None:
- if not name:
- name = config.app_name
- if not dbname:
- dbname = name
- db_path = _get_database_path(name, dbname)
+ def __init__(self, name=None, check_same_thread=False):
+ if name is None:
+ name = config.app_config['database_name']
+ database_path = _get_database_path(name)
+ if not os.path.exists(os.path.dirname(database_path)):
+ os.makedirs(os.path.dirname(database_path))
self.logger = logging.getLogger(self.__class__.__name__)
- self.sqlite = sqlite3.connect(db_path, check_same_thread=check_same_thread)
+ self.sqlite = sqlite3.connect(database_path, check_same_thread=check_same_thread)
if is_development_mode():
self.sql_logger = logging.getLogger(self.__class__.__name__)