stevegrossi / habits

An Elixir/Phoenix app for tracking daily habits, ready to deploy to Heroku.
62 stars 7 forks source link

Extract a database view for streaks to enable simpler and more powerful querying #4

Closed stevegrossi closed 7 years ago

stevegrossi commented 7 years ago

I ❤️ ❤️ ❤️ how you can build Ecto schemas on top of database views just like you can with tables. This let me push the data logic for streaks down into the database and allow a much simpler querying syntax (no raw SQL) in the Elixir code. A refactor of the streaks query also enabled richer querying, such as for the longest streak as well as the current one:

screen shot 2017-01-12 at 5 59 21 am