PHP code example of forrest79 / phpgsql-nette

1. Go to this page and download the library: Download forrest79/phpgsql-nette library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

forrest79 / phpgsql-nette example snippets


$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();

$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));
}

$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);