Skip to content

Commit e86e08d

Browse files
committed
Merge pull request #358 from cakephp/sqlformat
Format SQL queries so they are easier to read.
2 parents 10e7a73 + 0b42ea6 commit e86e08d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"source": "https://github.com/cakephp/debug_kit"
2424
},
2525
"require": {
26-
"cakephp/cakephp": "3.0.*"
26+
"cakephp/cakephp": "3.0.*",
27+
"jdorn/sql-formatter": "~1.2"
2728
},
2829
"require-dev": {
2930
"cakephp/cakephp-codesniffer": "dev-master",

src/Template/Element/sql_log_panel.ctp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
* @license http://www.opensource.org/licenses/mit-license.php MIT License
1717
*/
1818
$noOutput = true;
19+
20+
// Configure sqlformatter colours.
21+
SqlFormatter::$quote_attributes = 'style="color: #004d40;"';
22+
SqlFormatter::$backtick_quote_attributes = 'style="color: #26a69a;"';
23+
SqlFormatter::$number_attributes = 'style="color: #ec407a;"';
24+
SqlFormatter::$word_attributes = 'style="color: #9c27b0;"';
25+
SqlFormatter::$pre_attributes = 'style="color: #222; background-color: transparent;"';
1926
?>
2027

2128
<?php if (!empty($tables)): ?>
@@ -63,7 +70,7 @@ $noOutput = true;
6370
<tbody>
6471
<?php foreach ($queries as $query): ?>
6572
<tr>
66-
<td><?= h($query['query']) ?></td>
73+
<td><?= SqlFormatter::format($query['query']) ?></td>
6774
<td><?= h($query['rows']) ?></td>
6875
<td><?= h($query['took']) ?></td>
6976
</tr>

0 commit comments

Comments
 (0)