Build Status Dependency Status Code Climate

An abstract SQL compiler for Alf expressions



This sub-module provides an abstract SQL compiler for Alf expressions. It is NOT aimed at being used by end-users (the API illustrated below is considered private and may change at any time). Instead, it provides a basis for concrete translators converting the resulting SQL abstract syntax tree to a concrete SQL dialect through third-party libraries.

See alf-sequel for a translator built on top of Sequel.


require 'alf-sql'

Alf.connect("sap.db") do |conn|
  # Let parse some relational expression
  expr = conn.parse{
    restrict(suppliers, city: 'London')

  # Translate to SQL
  # (non-portable SQL output unless you require alf-sequel as well)
  puts expr.to_sql
  # => SELECT t1.sid,, t1.status,
  #      FROM suppliers AS t1
  #     WHERE = 'London'

  # Alternatively (for translator implementers),
  # compile to an abstract cog (cannot be iterated)
  cog =

  # Let see the SQL AST
  puts cog.to_sexpr.inspect
  # => [ :select_exp, [:select_list, ...] ]