karlomikus / bar-assistant

Bar assistant is a all-in-one solution for managing your home bar

Home Page:https://barassistant.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Save ABV to database

karlomikus opened this issue · comments

  • Allows easier filtering and ordering via query strings

IIRC this project uses sqlite as a database backend, but more mature backends support computed columns, see https://www.postgresql.org/docs/current/ddl-generated-columns.html

For ABV calculation, since it's not too difficult, it could be made to be such a computed column, allowing filtering and ordering, while keeping the value up to date automatically when an alcohol volume changes, or an ingredient is updated.

I foresee that, as the project grows, ABV calculations might not happen when a related object is updated (because the calculation would not be triggered on the API side for some reason). To alleviate the risk, either a computed column, strict unit testing, or database hooks might be needed. Just a thought.

Thats a really cool feature, and I see that sqlite also supports it. But I dont want to move this logic into the database, Id rather have it in the app code, especially in a small app like this one.