Wrangle Your SQL With Arel
summary
Claims raw SQL can be replaced by composable Ruby query objects built with Arel, and demonstrates concretely: building a date_trunc month-first-gift subquery, producing repeating left join lateral offsets to make donor timelines, and assembling a cohort query that sums months into columns. Examples show using Arel::Nodes.build_quoted and unary nodes for intervals, running to_SQL and executing queries against Postgres in tests, and carrying the code from Rails 4.2 to 6.0 while relying on test coverage because Arel is a private API.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 0:41Example
- 1:42Posteco
- 3:04Strings
- 3:39Private APIs
- 5:16A Rail Code
- 6:52A Rail Objects
- 7:38Sequel
- 8:09Query Object
- 14:34Rails Integration
- 15:43Outro
related talks
35mAdvanced aRel: When ActiveRecord Just Isn't Enough
32mArel: The Ruby Relational Algebra Library
28mActive Record Scopes and Arel
25mActiveRecord can't do it? Arel can!
21mActiveRecord can't do it? Arel can!
05mHow to use Arel? Wrong answers only!
30mBuilding an ORM with AReL: Walking up the (AS)Tree.
49mZOMG WHY IS THIS CODE SO SLOW?
