Giter Site home page Giter Site logo

alf-sql's Introduction

Alf::Sql

Build Status Dependency Status Code Climate

An abstract SQL compiler for Alf expressions

Links

Synopsis

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.

Example

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.name, t1.status, t1.city
  #      FROM suppliers AS t1
  #     WHERE t1.city = 'London'

  # Alternatively (for translator implementers),
  # compile to an abstract cog (cannot be iterated)
  cog = Alf::Sql::Compiler.new.call(expr)

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

alf-sql's People

Contributors

blambeau avatar ygu avatar

Stargazers

Kent avatar Erol Fornoles avatar Peter Solnica avatar

Watchers

Martin Gamsjaeger avatar  avatar Louis Lambeau avatar James Cloos avatar  avatar

Forkers

keemotion

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.