Initial commit: CloudRestoreAS v1.0.0 - Aplicación completa de restauración automática SQL Server

This commit is contained in:
2026-01-25 16:53:00 -07:00
commit 854ffa116f
43 changed files with 6357 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
"""Repositorio para gestionar configuración."""
from typing import Optional, Any
import json
from datetime import datetime
from .database import db
class ConfigRepository:
"""Repositorio para operaciones con configuración."""
@staticmethod
def get(key: str, default: Any = None) -> Any:
"""
Obtiene un valor de configuración.
Args:
key: Clave de configuración
default: Valor por defecto si no existe
Returns:
Valor de configuración (deserializado de JSON)
"""
row = db.fetchone("SELECT value FROM config WHERE key = ?", (key,))
if not row:
return default
try:
return json.loads(row["value"])
except:
return row["value"]
@staticmethod
def set(key: str, value: Any):
"""
Establece un valor de configuración.
Args:
key: Clave de configuración
value: Valor a guardar (se serializa a JSON)
"""
now = datetime.utcnow().isoformat()
value_str = json.dumps(value) if not isinstance(value, str) else value
db.execute("""
INSERT OR REPLACE INTO config (key, value, updated_at)
VALUES (?, ?, ?)
""", (key, value_str, now))
@staticmethod
def get_all() -> dict:
"""
Obtiene toda la configuración.
Returns:
Diccionario con todas las claves y valores
"""
rows = db.fetchall("SELECT key, value FROM config")
config = {}
for row in rows:
try:
config[row["key"]] = json.loads(row["value"])
except:
config[row["key"]] = row["value"]
return config
@staticmethod
def delete(key: str):
"""Elimina una clave de configuración."""
db.execute("DELETE FROM config WHERE key = ?", (key,))