# Erlang Embedded SQL library

This library allows you to represent SQL sentences as Erlang
terms. Please, consider it as a failed **proof of concept**, it is
incomplete and we do not recommend to be used in production.

A pretty print function generates SQL in the form of an Extended
Query: `iodata()` + parameters. The is directly usable in second and
third parameter of `epgsql:equery/3`. The SQL string (`iodata()`) is
directly used in the second argument of `epgsql:parse/2`.

## Usage

Let's write a representation of this SQL query:

SELECT, emails.address FROM users INNER JOIN emails ON =

In eesql, the following term represents the previous query:

Q = #select{
      columns = ['','emails.address'],
      from = [#join{type = inner,
                    left = users
                    right = emails
                    on = {'','=',''}}]

Now, you can generate the SQL ready for the actual query:

1> {S,P} = eesql:to_sql(Q).
{[["SELECT ","ALL"," ",
   [<<"">>,", ",<<"emails.address">>],
   [" FROM ",
      [["INNER",32,"JOIN ",<<"emails">>,32,"ON",32,
        [<<"">>," ",<<"=">>," ",<<"emails.i"...>>]]]]]],

Just to check:

2> iolist_to_binary(S).
<<"SELECT ALL, emails.address FROM users INNER JOIN emails ON =;">>

You can find more usage examples in `tests/eesql_tests.erl`.