mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-10-03 18:48:08 +00:00
28 lines
700 B
Python
28 lines
700 B
Python
from typing import List
|
|
from peewee import Model, Database
|
|
from .models import BackupPlanModel, DestinationModel
|
|
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
|
|
|
|
|
class DatabaseManager(DatabaseManagerPort):
|
|
models: List[Model] = [
|
|
BackupPlanModel,
|
|
DestinationModel,
|
|
]
|
|
|
|
def __init__(self, db: Database):
|
|
self.db = db
|
|
self._update_model_meta()
|
|
self.create_tables()
|
|
|
|
def _update_model_meta(self):
|
|
for model in self.models:
|
|
model._meta.database = self.db
|
|
|
|
def get_connection(self):
|
|
return self.db
|
|
|
|
def create_tables(self):
|
|
with self.db:
|
|
self.db.create_tables(self.models, safe=True)
|