You've already forked explain.depesz.com
mirror of
https://gitlab.com/depesz/explain.depesz.com.git
synced 2025-07-17 01:42:34 +02:00
use Pg::SQL::PrettyPrinter by default
This commit is contained in:
1
cpanfile
1
cpanfile
@ -20,5 +20,6 @@ requires 'File::Spec';
|
|||||||
requires 'Mojolicious';
|
requires 'Mojolicious';
|
||||||
requires 'Pg::Explain', '>= 2.1';
|
requires 'Pg::Explain', '>= 2.1';
|
||||||
requires 'Number::Bytes::Human';
|
requires 'Number::Bytes::Human';
|
||||||
|
requires 'Pg::SQL::PrettyPrinter';
|
||||||
|
|
||||||
# vim: set ft=perl:
|
# vim: set ft=perl:
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
"title" : "explain.depesz.com",
|
"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",
|
"secret" : "|Erp--Wjgb)+eiB/|H=|V7!#+M|L{a8=J2|pd+N1=M|&pJWq|M&,f3q^XS",
|
||||||
|
|
||||||
"database" : {
|
"database" : {
|
||||||
|
@ -4,9 +4,11 @@ use Mojo::Base 'Mojolicious::Controller';
|
|||||||
|
|
||||||
use English -no_match_vars;
|
use English -no_match_vars;
|
||||||
|
|
||||||
|
use Data::Dumper;
|
||||||
use Pg::Explain;
|
use Pg::Explain;
|
||||||
use Pg::Explain::Hinter;
|
use Pg::Explain::Hinter;
|
||||||
use pgFormatter::Beautify;
|
use pgFormatter::Beautify;
|
||||||
|
use Pg::SQL::PrettyPrinter;
|
||||||
use Encode;
|
use Encode;
|
||||||
use Email::Valid;
|
use Email::Valid;
|
||||||
use Config;
|
use Config;
|
||||||
@ -344,11 +346,34 @@ sub show {
|
|||||||
$self->stash->{ title } = $data->{ 'title' };
|
$self->stash->{ title } = $data->{ 'title' };
|
||||||
my $query = $data->{ 'query' } // $explain->query;
|
my $query = $data->{ 'query' } // $explain->query;
|
||||||
if ( $query ) {
|
if ( $query ) {
|
||||||
my $beautifier = pgFormatter::Beautify->new();
|
my $pretty;
|
||||||
$beautifier->query( $query );
|
eval {
|
||||||
$beautifier->beautify();
|
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->{ query } = $query;
|
||||||
}
|
}
|
||||||
$self->stash->{ stats } = $stats;
|
$self->stash->{ stats } = $stats;
|
||||||
|
Reference in New Issue
Block a user