forrest79 / phpgsql-nette
Use PhPgSql with Tracy from Nette Framework.
Requires
- php: ^8.3
- forrest79/phpgsql: ^2.0
- tracy/tracy: ^2.10
Requires (Dev)
- doctrine/sql-formatter: ^1.5
- forrest79/phpcs: ^2.0
- forrest79/phpcs-ignores: ^0.5
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
- shipmonk/phpstan-rules: ^4.2
Suggests
- doctrine/sql-formatter: For better formating SQL queries to Tracy bar and bluescreen.
- dev-master
- v2.x-dev
- v2.0.0
- v1.6.5
- v1.6.4
- v1.6.3
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.0
- v0.10.0
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.9
- v0.8.8
- v0.8.7
- v0.8.6
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.1
- v0.7.0
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.1
- v0.3.0
- v0.2.0
- v0.1.0
This package is auto-updated.
Last update: 2025-10-01 21:16:23 UTC
README
Use PhPgSql with Tracy from Nette Framework.
Introduction
Tracy bar panel to show queries executed in your database and bluescreen extension to show failed database query.
Installation
The recommended way to install PhPgSql - Tracy is through Composer:
composer require forrest79/phpgsql-nette
Using
Bar panel
Bar panel will show all queries executed in your database. You copy query to the clipboard, mark long run queries, mark repeated queries, show notices and non parsed columns.
You can add the panel for each database connection:
$tracyBar = Tracy\Debugger::getBar(); // or instance get from DI container or somewhere else $connection = new Forrest79\PhPgSql\Db\Connection(); // or instance get from DI container or somewhere else $queryDumper = new PhPgSql\Tracy\QueryDumpers\SqlFormatter(); // or some other query dumper $name = 'Main connection'; // just to recognize two different bars $barPanel = PhPgSql\Tracy\BarPanel::initialize( $tracyBar, $connection, $queryDumper, $name, explain: false, // when true, explain is execute and show for all queries notices: false, // when true, notices are get from the database and show with the queries longQueryTimeMs: null, // if you set some value in miliseconds, long running queries will be marked detectRepeatingQueries: false, // when true, repeating queries will be detected and marked detectNonParsedColumns: false, // when true, non-used columns wil be detected and show for each query backtraceContinueIterate: null, // used for detection where the query was executed in the PHP code - callable, more about this later showMaxLastQueries: null, // show only last queries, when null - default value of 1000 queries is used, selected value otherwise ); // To disable bar panel $barPanel->disable();
- bar can be disabled with
disable()
method
$backtraceContinueIterate
parameter
Panel is showing links to the PHP source files, where the query was executed. This is made using PHP function debug_backtrace()
.
This function returns the whole call stack. To get the correct place in the PHP source file, we must ignore some internal library classes where the query
is really executed and iterated up to the user code, that run this execution.
Basically, BarPanel
ignores all classes/function from PhPgSql library to show the most accurate place in the PHP source.
When you use some own custom wrapping objects, you want to ignore it in the call stack as well. You can some callable and pass it to the $backtraceContinueIterate
Parameter. For example:
$backtraceContinueIterate = function (string $class, string $function): bool { return (is_a($class, MyOwn\Database\Repository::class, true) && in_array($function, ['get', 'insert', 'insertReturning', 'multiInsert', 'update', 'updateReturning', 'saveBy', 'delete', 'deleteReturning', 'getNextId'], true)) || (is_a($class, MyOwn\Database\Transaction::class, true) && in_array($function, ['execute', 'beginSmart', 'commitSmart', 'rollbackSmart'], true)) || (is_a($class, MyOwn\Database\DbFunction::class, true) && in_array($function, ['fetch', 'run', 'from'], true)) || (is_a($class, MyOwn\Database\Fluent\Query::class, true) && in_array($function, ['count', 'exists', 'fetchSingleValue'], true)); }
Bluescreen
Bluescreen should be registered just once (it doesn't matter how many DB connections you have):
$tracyBlueScreen = Tracy\Debugger::getBlueScreen(); // or instance get from DI container or somewhere else $queryDumper = new PhPgSql\Tracy\QueryDumpers\SqlFormatter(); // or some other query dumper PhPgSql\Tracy\BlueScreenPanel::initialize($tracyBlueScreen, $queryDumper);
With this, when some Forrest79\PhPgSql\Db\Exceptions\QueryException
is thrown, you will see the SQL query and the parameters (and the SQL query with the parameters) on your BlueScreen.
Query dumper
SQL queries are dumped in Tracy\Bar
and in Tracy\BlueScreen
and you can use different dumpers/formatters. Three are included:
PhPgSql\Tracy\QueryDumpers\NullDumper
- show SQL query as it isPhPgSql\Tracy\QueryDumpers\Basic
- highlight and format SQL query with basic internal formatterPhPgSql\Tracy\QueryDumpers\SqlFormatter
- highlight and format SQL query with Doctrine\Sql-Formatter,Doctrine\Sql-Formatter
must be is installed (composer require doctrine/sql-formatter --dev
)
Or you can use your own query dumper, just create a class-extending abstract class PhPgSql\Tracy\QueryDumper
.