%% vim: ts=4 sw=4 et ft=erlang
%% This is a sample config file for sigma_sql
[
    {sql_bridge, [
        %% module_alias determines a shortened module that will be dynamically
        %% generated on compile. By default, it uses "db". So db calls could be
        %% called with db:q() instead of sigma_sql:q(). The value can be any
        %% valid module name (though be careful not to use a module that
        %% already exists in your system or the Erlang Runtime System
        {module_alias, db},

        %% built-in adapters:
        %% sql_bridge_mysql_otp | sql_bridge_epgsql
        {adapter, sql_bridge_mysql_otp},

        {host, "127.0.0.1"},

        %% Default PostgreSQL Port
        %{port, 5432},
        
        %% Default MySQLPort
        {port, 3306},
        
        {user, "sql_bridge_user"},
        {pass, "sql_bridge_test_password"},
        %% There are three different ways to determine database
        %%
        %% 1) All requests go to a single database:
        %%
        {lookup, sql_bridge_test},
        %%
        %%
        %% 2) Before a request is made, run a lookup as {Module, Function, Args}
        %%
        %%{lookup, {lookup_module, lookup_function, Arglist}},
        %%
        %% The above will determine the database name (and subsequent pool name) by calling the equivilant of
        %%
        %% erlang:apply(lookup_module, lookup_function, Arglist),
        %%
        %%
        %% 3) Shortcut for (2) calling a function with no arguments
        %%
        %%{lookup, {lookup_module, lookup_function}},
        %%
        %% The above is a shortcut equivilant of
        %%
        %% erlang:apply(lookup_module, lookup_function, []).
        %%
        %% Which is just a shortcut of
        %%
        %% lookup_module:lookup_function().
        %% 
        %% Using poolboy, the connections per pool will default to opening up 10 connections per pool
        {connections_per_pool, 10},

        %% Poolboy supports an overflow option, so that if all pools in the
        %% base list are in use, poolboy can spin up "overflow" pools. This
        %% option sets that limit.  This works with the epgsql and mysql_otp
        %% adapters. It does *NOT* do anything for the emysql legacy adapter.
        {overflow_connections_per_pool, 10},

        %% By default, string fields will be returned as binaries. If
        %% stringify_binaries is set to true, binary return values will be
        %% converted to strings (lists).
        {stringify_binaries, true},

        %% Replacement Token Style can be either of the following atoms:
        %% postgres | '$' | mysql | '?'
        %% postgres and '$' are equivilant, and will use PGSQL's "$1, $2, ..$X" syntax for replacement
        %% mysql and '?' are equivilant and will use MySQL's ?, ?, ?... ? syntax for replacement.
        %% 
        %% The following two examples are equivilant:
        %%
        %% Postgres Style:
        %% sigma_sql:q("select * from whatever where a=$1 and b=$2", ["smasher", "amazing"]),
        %%
        %% MySQL Style:
        %% sigma_sql:q("select * from whatever where a=? and b=?", ["smasher", "amazing"]),
        %%
        %% Keep in mind that using MySQL replacement will be faster with MySQL
        %% and Postgres replacement will be faster with Postgres, because the
        %% alternative requires doing some pre-processing witin sql_Bridge but
        %% if you're porting an app from one to another, this will work.
        {replacement_token_style, '$'}
    ]}
].
