The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Pg::SQL::PrettyPrinter - Pretty printing SQL queries

SYNOPSIS

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();

FUNCTIONS

new

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.

validate_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.

parse

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.

fetch_struct

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.

remove_irrelevant

Removes irrelevant parts of query, like prompts.

AUTHOR

hubert depesz lubaczewski, <depesz at depesz.com>

BUGS

Please report any bugs or feature requests to depesz at depesz.com.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Pg::SQL::PrettyPrinter