TODO: Add description
If available in Hex, the package can be installed
by adding sql_formatter
to your list of dependencies in mix.exs
:
def deps do
[
{:sql_formatter, "~> 1.0.0"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/sql_formatter.
SQLFormatter.format("SELECT * FROM users")
#=>
"""
SELECT
*
FROM
users
"""
This library provides functionality to test sql generation and compare it in a readable format.
First you'll need to configure your ExUnit formatter. In test/test_helper.exs
add to the top:
ExUnit.configure(formatters: [SQLFormatter.ExUnit.CLIFormatter])
In test modules you can then import assertions:
import SQLFormatter.Assertions
Then assert equality between sql strings:
assert_sql_equal "SELECT * FROM users", "SELECT * FROM users"
refute_sql_equal "SELECT * FROM users", "SELECT * FROM peons"
When used like this any SQL is formatted before comparison and when there are errors they're shown in a more readable format.
NOTE: Color diffing not shown below
1) test formats simple SQL (SQLFormatterTest)
test/sql_formatter_test.exs:7
SQL strings do not match
code: assert_sql_equal(unformatted_sql, formatted_sql)
left: """
SELECT
*
FROM
users
WHERE
id = 1
"""
right: """
SELECT
*
FROM
user
WHERE
id = 1
"""
stacktrace:
test/sql_formatter_test.exs:20: (test)