feat: Implement text manager API and database connection
- Added `text_manager.py` to handle the creation of text libraries via FastAPI. - Introduced database connection management in `conexion.py` using PostgreSQL credentials from environment variables. - Created abstract base class `EmbedderABC` in `Base_Embedder.py` for embedding models. - Developed `OpenAIEmbedder` class to generate embeddings using OpenAI's API. - Implemented `OpenAIEmbedderModel` and repository pattern for managing OpenAI embedders in `Openai_embedder_mmr.py`. - Established `Biblioteca` class for managing text libraries and their associated notes in `biblioteca.py`. - Created SQLAlchemy models and mappers for `Biblioteca` and `Nota` in `biblioteca_mmr.py` and `notas_biblioteca_mmr.py`. - Added functionality for dynamic table generation for notes associated with libraries. - Included comprehensive methods for adding, retrieving, and managing notes and libraries in their respective repositories.
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
from datetime import datetime, timezone
|
||||
from sqlalchemy import create_engine, text
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy.orm import sessionmaker, Session
|
||||
from sqlalchemy.engine import Engine
|
||||
|
||||
|
||||
from src.ConexionSql.Base_conexion import ConexionBase
|
||||
from src.Credenciales.postgres_credencial import PostgresCredencial
|
||||
|
||||
|
||||
class PostgresConexion(ConexionBase):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.estado = "pendiente"
|
||||
@@ -18,25 +19,29 @@ class PostgresConexion(ConexionBase):
|
||||
self.port = credencial.port
|
||||
self.dbname = credencial.dbname
|
||||
self.user = credencial.user
|
||||
self.password = credencial.password # se guarda la contraseña
|
||||
self.password = credencial.password
|
||||
uri = credencial.get_uri()
|
||||
else:
|
||||
self.user = kwargs.get("user")
|
||||
self.password = kwargs.get("password") # se guarda la contraseña
|
||||
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 = create_engine(uri)
|
||||
self.SessionLocal = sessionmaker(bind=self.engine)
|
||||
self._engine: Engine = create_engine(uri)
|
||||
self._Session = sessionmaker(bind=self._engine)
|
||||
|
||||
def get_session(self):
|
||||
return self.SessionLocal()
|
||||
|
||||
def get_session(self) -> Session:
|
||||
return self._Session()
|
||||
|
||||
def get_engine(self) -> Engine:
|
||||
return self._engine
|
||||
|
||||
def probar_conexion(self) -> bool:
|
||||
try:
|
||||
with self.engine.connect() as connection:
|
||||
with self._engine.connect() as connection:
|
||||
connection.execute(text("SELECT 1"))
|
||||
self.estado = "exito"
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user