View Source EctoDbg (EctoDbg v0.2.0)
This module exposes a macro that you can inject into your Repo module so
that you can pretty print SQL queries with the parameters espaced into the
query. Once you use
this module in your Repo module, you'll be able to
call the injected functions with your query and you can see the formatted
SQL that Ecto generates.
Warning
This library makes use of pgFormatter (which is a Perl script) in order to format your SQL queries. This is meant to be a tool that is used during development and should probably not be shipped with your production application. It is recommended that you add this library as only a dev/test dependency.
Link to this section Summary
Functions
By using this macro in your Repo module, you will get 6 additional functions added to your repo module. This functions are
Link to this section Functions
By using this macro in your Repo module, you will get 6 additional functions added to your repo module. This functions are:
all_and_log/1
andall_and_log/2
one_and_log/1
andone_and_log/2
update_all_and_log/1
andupdate_all_and_log/2
delete_all_and_log/1
anddelete_all_and_log/2
log_all_query/1
log_one_query/1
log_update_all_query/1
log_delete_all_query/1
The *_and_log
functions will output the query and will also execute it with the
corresponding Repo function (all
, update_all
, and delete_all
). The one and two
arity versions of these functions align with the Repo functions so that these functions
can be used as direct drop in replacements when you need to see what query is actually
being executed by Ecto. The log_*_query
functions will simply log out the generated
query without executing them.
This macro currently supports the following options that can be used to configured how it behaves:
:level
- Specifies the log level for when the SQL query is logged (default::debug
).:logger_function
- Specifies the module+function that will be invoked when logging an SQL query. The provided module+function must have an arity of 4 and accept the following parameters:repo, action, formatted_sql, opts
where opts are the options that were passed to theuse EctoDbg
macro. The default value is:{EctoDbg, :default_logger}
.