Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Spelunking through Arel

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for alassek alassek
September 06, 2016

Spelunking through Arel

Arel is the underlying API that ActiveRecord uses to construct SQL queries. But how does it actually work?

Avatar for alassek

alassek

September 06, 2016

More Decks by alassek

Other Decks in Programming

Transcript

  1. Consider a compiler that represents programs as abstract syntax trees.

    It will need to perform operations on abstract syntax trees for "static semantic" analyses like checking that all variables are defined. It will also need to generate code. So it might define operations for type- checking, code optimization, flow analysis, check for variables being assigned values before they're used, and so on. Moreover, we could use the abstract syntax trees for pretty- printing, program restructuring, code instrumentation, and computing various metrics of a program. ”
  2. SQL Visitor SELECT "users".* FROM "users" WHERE "users"."name" ILIKE 'adam%'

    AND "users"."created_at" BETWEEN '2016-01-01' AND '2016-09-01' ORDER BY "users"."created_at" DESC LIMIT 100