32 lines
735 B
Python
32 lines
735 B
Python
import sqlite3
|
|
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
from repository.abstract_db_repository import AbstractDatabaseRepository
|
|
|
|
from repository.sqlite_init_tables import (
|
|
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()
|