Alf::Sequel

Build Status Dependency Status

A DBMS adapter for Alf built atop Sequel.

Links

Synopsis

Extends alf-sql in such a way that most existing SQL databases can be used with Alf thanks to the awesome Sequel library.

Example

require 'alf-sequel'

Alf.connect("sap.db") do |conn|

  # Send a query and puts the result
  # (See Alf main docs for smarter ways of using query results)
  relation = conn.query{
    restrict(suppliers, city: 'London')
  }

  puts relation
  # => +------+-------+---------+--------+
  #    | :sid | :name | :status | :city  |
  #    +------+-------+---------+--------+
  #    | S1   | Smith |      20 | London |
  #    | S4   | Clark |      20 | London |
  #    +------+-------+---------+--------+

  # alf-sequel overrides `Operand#to_sql` in such a way that the resulting
  # SQL code is handled by Sequel itself and thus valid for the DBMS
  # considered
  sql = conn.parse{
    restrict(suppliers, city: 'London')
  }.to_sql

  puts sql
  # => SELECT `t1`.`sid`, `t1`.`name`, `t1`.`status`, `t1`.`city`
  #      FROM `suppliers` AS 't1'
  #     WHERE (`t1`.`city` = 'London')
end