Skip to content

Commit b707764

Browse files
author
Xavier Barbosa
committed
Updated query rendered with new styling.
1 parent f420e57 commit b707764

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

src/Renderers/AbstractRenderer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Madewithlove\LaravelDebugConsole\Renderers;
44

55
use Madewithlove\LaravelDebugConsole\Renderers\Contracts\RendererInterface;
6+
use Symfony\Component\Console\Input\InputInterface;
67
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Style\SymfonyStyle;
79

810
abstract class AbstractRenderer implements RendererInterface
911
{
@@ -13,10 +15,11 @@ abstract class AbstractRenderer implements RendererInterface
1315
protected $output;
1416

1517
/**
18+
* @param \Symfony\Component\Console\Input\InputInterface $input
1619
* @param \Symfony\Component\Console\Output\OutputInterface $output
1720
*/
18-
public function __construct(OutputInterface $output)
21+
public function __construct(InputInterface $input, OutputInterface $output)
1922
{
20-
$this->output = $output;
23+
$this->output = new SymfonyStyle($input, $output);
2124
}
2225
}

src/Renderers/Query.php

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,33 @@ class Query extends AbstractRenderer
1212
public function render(array $data)
1313
{
1414
$queries = collect(array_get($data, 'queries.statements', []));
15+
$message = sprintf(
16+
'%s statements were executed in %s',
17+
array_get($data, 'queries.nb_statements'),
18+
array_get($data, 'queries.accumulated_duration_str')
19+
);
1520

16-
// Retrieve grouped sql statements
17-
$rows = $queries
18-
->map(function ($query, $index) {
19-
return [
20-
$index,
21-
array_get($query, 'sql'),
22-
array_get($query, 'duration_str'),
23-
];
24-
})
25-
->all();
21+
$this->output->title('Queries');
22+
$this->output->writeln($message);
2623

2724
$table = new Table($this->output);
28-
29-
$this->output->writeln('Queries executed:');
3025
$table
3126
->setHeaders([
32-
'N.',
3327
'SQL',
3428
'Duration',
29+
'Statement ID',
30+
'connection',
3531
])
36-
->setRows($rows)
37-
->render();
38-
39-
$this->output->writeln('Queries summary:');
40-
$table
41-
->setHeaders([
42-
'Total Number of Queries',
43-
'Total Execution Time',
44-
])
45-
->setRows([
46-
[
47-
array_get($data, 'queries.nb_statements'),
48-
array_get($data, 'queries.accumulated_duration_str')
49-
]
50-
])
32+
->setRows(
33+
$queries->map(function ($query, $index) {
34+
return [
35+
array_get($query, 'sql'),
36+
array_get($query, 'duration_str'),
37+
array_get($query, 'stmt_id'),
38+
str_limit(array_get($query, 'connection'), 20),
39+
];
40+
})
41+
->all())
5142
->render();
5243
}
5344
}

0 commit comments

Comments
 (0)