1
0
mirror of https://gitlab.com/depesz/explain.depesz.com.git synced 2025-02-21 19:48:37 +02:00

use Pg::SQL::PrettyPrinter by default

This commit is contained in:
Hubert depesz Lubaczewski 2022-08-31 12:44:27 +02:00
parent 0a90bc39b6
commit 8cb75daed5
3 changed files with 32 additions and 4 deletions

View File

@ -20,5 +20,6 @@ requires 'File::Spec';
requires 'Mojolicious';
requires 'Pg::Explain', '>= 2.1';
requires 'Number::Bytes::Human';
requires 'Pg::SQL::PrettyPrinter';
# vim: set ft=perl:

View File

@ -1,6 +1,8 @@
{
"title" : "explain.depesz.com",
"parser-url" : "http://127.0.0.1:15283/",
"secret" : "|Erp--Wjgb)+eiB/|H=|V7!#+M|L{a8=J2|pd+N1=M|&pJWq|M&,f3q^XS",
"database" : {

View File

@ -4,9 +4,11 @@ use Mojo::Base 'Mojolicious::Controller';
use English -no_match_vars;
use Data::Dumper;
use Pg::Explain;
use Pg::Explain::Hinter;
use pgFormatter::Beautify;
use Pg::SQL::PrettyPrinter;
use Encode;
use Email::Valid;
use Config;
@ -344,11 +346,34 @@ sub show {
$self->stash->{ title } = $data->{ 'title' };
my $query = $data->{ 'query' } // $explain->query;
if ( $query ) {
my $beautifier = pgFormatter::Beautify->new();
$beautifier->query( $query );
$beautifier->beautify();
my $pretty;
eval {
my $pspp = Pg::SQL::PrettyPrinter->new(
'service' => $self->app->config->{ 'parser-url' },
'sql' => $query,
);
$pspp->parse();
$pretty = join( ";\n\n", map { $_->pretty_print } @{ $pspp->{ 'statements' } } ) . ";\n";
$pretty .= "-- Formatted by Pg::SQL::PrettyPrinter\n";
};
if ( $EVAL_ERROR ) {
$self->app->log->error(
"beautifying query failed: " . Dumper(
{
'id' => $id,
'query' => $query,
'error' => $EVAL_ERROR->message
}
)
);
my $beautifier = pgFormatter::Beautify->new();
$beautifier->query( $query );
$beautifier->beautify();
$pretty = $beautifier->content();
$pretty .= "-- Formatted by pgFormatter::Beautify\n";
}
$self->stash->{ bquery } = $beautifier->content();
$self->stash->{ bquery } = $pretty;
$self->stash->{ query } = $query;
}
$self->stash->{ stats } = $stats;