nfaiz/dbtoolbar

CodeIgniter 4 Database Debug Toolbar Query Highlighter.

v1.0.1 2024-04-22 05:53 UTC

This package is auto-updated.

Last update: 2024-11-22 07:08:40 UTC


README

GitHub GitHub repo size Hits

Query Highlighter

Description

CodeIgniter 4 Database Debug Toolbar Query Highlighter.

Table of contents

Requirement

Installation

Install library via composer:

composer require nfaiz/dbtoolbar

Query Highlighter is located at DbQueries tab (Debug Toolbar)

Configuration

Remove Default Database Tab

  1. Open and comment Database::class from $collectors property in app/Config/Toolbar.php.
public array $collectors = [
    // Database::class,
];
  1. Open and comment Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect'); in app/Config/Events.php.
if (CI_DEBUG && ! is_cli()) {
  // Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
  Services::toolbar()->respond();
}

Modify Settings.

Open and add properties below in app/Config/Toolbar.php accordingly.

/**
 * -------------------------------------------------------------
 * Disable DbToolbar query Highlighter
 * -------------------------------------------------------------
 * 
 * To disable DbToolbar query highlighter, change value to true
 *
 * @var bool
 */
public bool $dbToolbarDisable = false;

/**
 * -------------------------------------------------------------
 * DbToolbar Theme
 * -------------------------------------------------------------
 * 
 * Configuration for light and dark mode SQL Syntax Highlighter.
 * Refer https://github.com/scrivo/highlight.php/tree/master/src/Highlight/styles or
 * use \HighlightUtilities\getAvailableStyleSheets(); for available stylesheets.
 *
 * @var array
 */
public array $dbToolbarTheme = [
    'light' => 'atom-one-light',
    'dark'  => 'atom-one-dark'
];

/**
 * -------------------------------------------------------------
 * DbToolbar View
 * -------------------------------------------------------------
 * 
 * To override DbToolbar SQL Syntax Highlighter view.
 *
 * @var array
 */
public string $dbToolbarTpl = 'Nfaiz\DbToolbar\Views\database.tpl';

/**
 * -------------------------------------------------------------
 * Bottom Margin Between Diplayed Query in Toolbar
 * -------------------------------------------------------------
 * 
 * Value in px
 * 
 * @var int
 */
public int $dbToolbarMarginBottom = 4;

/**
 * -------------------------------------------------------------
 * Log Queries
 * -------------------------------------------------------------
 *
 * Please set threshold to minimum 7 at app/Config/Logger.php
 * Logs can be found at ROOTPATH/writable/logs
 *
 * @var boolean
 */
public bool $dbToolbarLogger = false;

Custom Syntax Highlighter view.

Open app/Config/Toolbar.php and add/edit template view file using $dbToolbarTpl property.
You can create your own view and you change it accordingly. For Example public $dbToolbarTpl = dbtoolbar/database;

Views/dbtoolbar/database.php.

{! hlstyle !}
<table>
    <thead>
        <tr>
            <th class="debug-bar-width6r">Time</th>
            <th>Query String</th>
        </tr>
    </thead>
    <tbody>
    {queries}
        <tr class="{class}" title="{hover}" data-toggle="{qid}-trace">
            <td class="narrow" style="vertical-align: top;">{duration}</td>
            <td><u>{trace-file}</u>{! sql !}</td>
        </tr>
        <tr class="muted debug-bar-ndisplay" id="{qid}-trace">
            <td></td>
            <td>
            {trace}
                {index}<strong>{file}</strong><br/>
                {function}<br/><br/>
            {/trace}
            </td>
        </tr>
    {/queries}
    </tbody>
</table>

Screenshot

Default Database Toolbar

  • Light

Light mode

  • Dark

Dark mode

Using DbToolbar

  • Light

Light mode

  • Dark

Dark mode

Credit