Skip to content

Instantly share code, notes, and snippets.

@apetrov
Created December 13, 2018 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apetrov/e130794f8c2fbe917f00f5b9b18e0e39 to your computer and use it in GitHub Desktop.
Save apetrov/e130794f8c2fbe917f00f5b9b18e0e39 to your computer and use it in GitHub Desktop.
select [user_id, sum(payout),sum(fee).as(fee)], from: :transactions do
join :users do
users :id
transactions :user_id
end
groupby :user_id
where { user_id [1,2,3] }
where { fee > 40 }
order "sum(payout)", :desc
end
# Thinking of building a readable alternative for AREL.
# Must have feature is to make it composable in a similar way but
# Avoid a pit-fall of the over-complicated syntax.
# I haven't fininshed with the final version of the syntax yet,
# But once it's done, that's a fairly straightforward to make it work.
# also stumble across a similar project (10 year old!)
# https://github.com/semenov/boroda
# but it lack composablity and syntax could have been better.
#
# one more thing from my experience:
# in 99.9% of complicated queries, it's all about producing select statements for
# a reporting purposes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment