Model/backend/app/db/functions/materials_functions.py
2023-10-10 05:41:25 +08:00

19 lines
713 B
Python

from backend.app.db.models.materials import Material
from functools import lru_cache
@lru_cache(maxsize=128)
def get_materials(session):
"""
This function will retrieve all materials from the database.
:return: A list of Material objects if successful, an empty list otherwise.
TODO: It might not be the best choice to store the materials data in a database table since thi
table probably won't be very large and won't be updated that often. It might be better to
store this data in s3 load it into memory when the app starts up. We will test this
"""
materials = session.query(Material).filter(Material.is_active).all()
return materials if materials else []