Skip to content

Commit 525fdff

Browse files
authored
Merge pull request #6 from trybeapp/dump-query
refactor: better query debug
2 parents 07cd177 + cf0a12f commit 525fdff

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/Connection.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,33 @@ public function logQuery($query, $bindings, $time = null)
247247
}
248248
}
249249

250+
/**
251+
* @return array
252+
*/
253+
public function getQueryLogJson(): array
254+
{
255+
return array_map(
256+
function ($log) {
257+
return str_replace(' ', ' ', json_encode($log['query']['body'], JSON_PRETTY_PRINT));
258+
},
259+
$this->getQueryLog()
260+
);
261+
}
262+
263+
/**
264+
* @return void
265+
*/
266+
public function dumpQueryLogJson(): void
267+
{
268+
print '<pre>';
269+
270+
foreach ($this->getQueryLogJson() as $query) {
271+
print $query . "\n\n";
272+
}
273+
274+
print '</pre>';
275+
}
276+
250277
/**
251278
* Prepare the query bindings for execution.
252279
*

src/QueryGrammar.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ public function compileSelect(Builder $builder): array
6565
unset($params['body']['query']);
6666
}
6767

68-
// print "<pre>";
69-
// print str_replace(' ', ' ', json_encode($params, JSON_PRETTY_PRINT));
70-
// exit;
71-
7268
return $params;
7369
}
7470

0 commit comments

Comments
 (0)