This repository has been archived on 2023-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
2023-01-10 00:48:55 +00:00
|
|
|
import sqlite3
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import Optional
|
|
|
|
|
2023-01-10 12:33:52 +00:00
|
|
|
from repository.abstract_db_repository import AbstractDatabaseRepository
|
2023-01-10 00:48:55 +00:00
|
|
|
|
2023-01-10 12:33:52 +00:00
|
|
|
from repository.sqlite_init_tables import (
|
2023-01-10 00:48:55 +00:00
|
|
|
TELEGRAM_USER_MATRIX_CHATS_SQL,
|
|
|
|
TELEGRAM_USERS_SQL,
|
|
|
|
MATRIX_ROOMS_SQL,
|
|
|
|
)
|
|
|
|
|
|
|
|
TABLES_LIST = [
|
|
|
|
TELEGRAM_USER_MATRIX_CHATS_SQL,
|
|
|
|
TELEGRAM_USERS_SQL,
|
|
|
|
MATRIX_ROOMS_SQL,
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class SQLiteDatabaseRepository(AbstractDatabaseRepository):
|
|
|
|
def __init__(self, app, path: Path):
|
|
|
|
self.path = path
|
|
|
|
self.conn = sqlite3.connect(path)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_tables(self) -> None:
|
|
|
|
"""Init tables in database"""
|
|
|
|
|
|
|
|
for table in TABLES_LIST:
|
|
|
|
self.conn.execute(table)
|
|
|
|
self.conn.commit()
|