ISCOUTB / AG-AgricultureCompany

Is a system designed to manage different aspects of the agriculture such as crops, inventary, distribution and sales by providing tools for the recording, updating and tracking of key information related to agricultural production.
GNU Affero General Public License v3.0
1 stars 1 forks source link

Database v1.0 #22

Open mogi22210 opened 2 months ago

mogi22210 commented 2 months ago

Se adjunta el archivo database relacionado al modelado de datos entregado hasta el momento.

mogi22210 commented 1 month ago

Importaciones de metodos de bases de datos sqlaalchemy y otros métodos.

from sqlalchemy import create_engine, Column, Integer, String, Float, Date from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, Session import os

URL de la base de datos PostgreSQL

DATABASE_URL = 'postgresql://adm:12345@localhost/mydatabase'

Configurar SQLAlchemy

engine = create_engine(DATABASE_URL) SessionLocal = sessionmaker(bind=engine) Base = declarative_base()

Crear una dependencia para obtener la sesión de base de datos en cada request

def get_db(): db = SessionLocal() try: yield db finally: db.close()