Pg::SQL::PrettyPrinter - Pretty printing SQL queries
Formats SQL queries "nicely". To do so it first has to parse it, and for this it's using microservice available over HTTP: https://gitlab.com/depesz/pg-query-parser-microservice.
Usage example:
use Pg::SQL::PrettyPrinter; my $pp = Pg::SQL::PrettyPrinter->new( 'service' => 'http://127.0.0.1:15283/', 'sql' => 'select 1' ); my $nice = $pp->pretty_print();
Object constructor.
Takes following arguments:
sql : obligatory query that will be pretty-printed
service : usually obligatory url to parsing microservice
struct : data structure that was obtained from the parsing microservice separately
Normally one will provide sql and service, but for testing purposes one can skip service and instead provide struct, which should be perl hash that is exactly what is being sent from the parser as JSON.
sql
service
struct
Checks if given structure (either from constructor's struct field, or obtained after deserializing JSON obtained from parsing microservice) matches some basic assumptions on what should be there.
In case of problems, exception is raised.
Wraps all work related with gettin data from struct given to constructor, or from parsing sql into tree of perl objects that will be responsible for pretty printing.
In case anything goes wrong - it will raise an exception.
Sends sql that was given to new() call to parsing microservice, deserializes it's output, and calls validate_struct to make sure that the result is sane.
validate_struct
Removes irrelevant parts of query, like prompts.
hubert depesz lubaczewski, <depesz at depesz.com>
<depesz at depesz.com>
Please report any bugs or feature requests to depesz at depesz.com.
depesz at depesz.com
You can find documentation for this module with the perldoc command.
perldoc Pg::SQL::PrettyPrinter
To install Pg::SQL::PrettyPrinter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pg::SQL::PrettyPrinter
CPAN shell
perl -MCPAN -e shell install Pg::SQL::PrettyPrinter
For more information on module installation, please visit the detailed CPAN module installation guide.