mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
15 lines
519 B
Python
15 lines
519 B
Python
from backend.app.db.connection import db_engine
|
|
from backend.app.db.models.materials import Material
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
|
|
def get_materials():
|
|
"""
|
|
This function will retrieve all materials from the database.
|
|
:return: A list of Material objects if successful, an empty list otherwise.
|
|
"""
|
|
Session = sessionmaker(bind=db_engine)
|
|
with Session() as session:
|
|
materials = session.query(Material).filter(Material.is_active).all()
|
|
|
|
return materials if materials else []
|