Ecto - Using select_merge for flexible aggregates
Problem PostgreSQL is a rock solid database. I've been using aggregate expressions for a number of features over the past few years in various languages. They can be used to build powerful features for your platform. When teamed up with Elixir and Ecto, you get amazing flexibility in your query generation. Typically the data you want to retrieve via a select is fairly static, or there are only one or two different versions of the select you need. @ doc """ Returns an aggregation of user activity """ @ spec user_activity_history () :: UserActivityHistory def user_activity_history () do query = from ( u in User , select : %UserActivityHistory { captured_at : fragment ( "now()" ) , hour_1 : filter ( count ( u . id ) , fragment ( "? >= now() - interval '1 hour'" , u . last_active )) , hour_6 : filter ( count ( u . id ) , fragment ( "...