aef8791151
- Added Appshell component with responsive navbar and main content area - Integrated ColorSchemeToggle for light/dark mode switching - Created Welcome component with styled title and introductory text - Developed ChatPage for LLM interaction with WebSocket support - Implemented Biblioteca for managing notes with rich text editor - Added LoginPage for user authentication with error handling - Introduced MessageList and MessageBubble components for chat messages - Styled components with CSS modules for consistent design
59 lines
2.1 KiB
Python
59 lines
2.1 KiB
Python
from datetime import datetime, timezone
|
|
from sqlalchemy import create_engine, text
|
|
from sqlalchemy.exc import SQLAlchemyError
|
|
from sqlalchemy.orm import sessionmaker, Session
|
|
from sqlalchemy.engine import Engine
|
|
|
|
from domains.ConexionSql.Base_conexion import ConexionBase
|
|
from domains.Credenciales.postgres_credencial import PostgresCredencial
|
|
|
|
class PostgresConexion(ConexionBase):
|
|
def __init__(self, *args, **kwargs):
|
|
self.estado = "pendiente"
|
|
self.timestamp = datetime.now(timezone.utc)
|
|
|
|
if args and isinstance(args[0], PostgresCredencial):
|
|
credencial = args[0]
|
|
self.host = credencial.host
|
|
self.port = credencial.port
|
|
self.dbname = credencial.dbname
|
|
self.user = credencial.user
|
|
self.password = credencial.password
|
|
uri = credencial.get_uri()
|
|
else:
|
|
self.user = kwargs.get("user")
|
|
self.password = kwargs.get("password")
|
|
self.host = kwargs.get("host")
|
|
self.port = kwargs.get("port", 5432)
|
|
self.dbname = kwargs.get("db") or kwargs.get("dbname")
|
|
uri = f"postgresql://{self.user}:{self.password}@{self.host}:{self.port}/{self.dbname}"
|
|
|
|
self._engine: Engine = create_engine(uri)
|
|
self._Session = sessionmaker(bind=self._engine)
|
|
|
|
# ✅ INICIALIZAR LA SESIÓN AQUÍ
|
|
self._session_instance: Session | None = None
|
|
|
|
def get_session(self) -> Session:
|
|
if self._session_instance is None:
|
|
self._session_instance = self._Session()
|
|
return self._session_instance
|
|
|
|
def get_engine(self) -> Engine:
|
|
return self._engine
|
|
|
|
def probar_conexion(self) -> bool:
|
|
try:
|
|
with self._engine.connect() as connection:
|
|
connection.execute(text("SELECT 1"))
|
|
self.estado = "exito"
|
|
return True
|
|
except SQLAlchemyError:
|
|
self.estado = "fallo"
|
|
return False
|
|
|
|
def close(self):
|
|
if self._session_instance is not None:
|
|
self._session_instance.close()
|
|
self._session_instance = None
|