The ActiveRecordLite Visualizer is a tool that I built on my off-time during my time at App Academy in order to show off another tool that I had made: ActiveRecordLite. ARL is a clone of some of the basic functionality offered by ActiveRecord. It was born out of an attempt to practice some metaprogramming techniques that I had just learned, and grew into something a little more serious. Essentially, it uses the SQLite3 gem to establish a connection to a sqlite database and gather information about the tables present and their appurtenant columns. It then uses this information to create a new Ruby class for each table, and a set of query methods for those classes, based again on table information. These methods make use of a homespun SQL AST manager (SastMan) which allows them to be chained arbitrarily.

SastMan is in essence a top-down parser of a certain subset of SQL SELECT statements (check the documentation for specifics). It generates an abstract syntax tree of a given statement by performing lexical and syntactic analysis on a query string. In particular, a lexer passes over a string literal, returning an array of tokens. The tokens are then passed to the parser, which generates the AST by using a technique known as recursive descent, specifically implementing Dijkstra’s Shunting Yard Algorithm for parsing operator precedence.