Download the PHP package huubverbeek/query-watcher without Composer
On this page you can find all versions of the php package huubverbeek/query-watcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download huubverbeek/query-watcher
More information about huubverbeek/query-watcher
Files in huubverbeek/query-watcher
Package query-watcher
Short Description A package to watch queries in your Laravel application -- including PHPUnit asserts.
License MIT
Informations about the package query-watcher
QueryWatcher
QueryWatcher is a composer package for Laravel that allows you to monitor and analyze database queries executed during the runtime of your application. It provides methods to track slow queries and identify duplicate queries.
Installation
You can install the QueryWatcher package via Composer by running the following command:
composer require huubverbeek/query-watcher
Requirements
This package requires php 8.1 or higher.
Usage
To start watching queries, you can use the watch
method provided by the QueryWatcher
facade:
This will enable the query watcher and start collecting executed queries.
All Queries
To retrieve all the queries you can use the queries
method:
Slow Queries
To retrieve the slow queries (queries that exceed a certain execution time), you can use the slowQueries
method:
You can also set a custom threshold (the default is one second) for slow queries by using the setSlowThreshold
method:
Duplicate Queries
To identify duplicate queries (queries with the same SQL statement and bindings), you can use the duplicateQueries
method:
Assertions
The QueryWatcher package also provides assertion methods to facilitate testing. These methods allow you to assert whether certain conditions are met based on the executed queries.
assertHasDuplicateQueries
: Assert that duplicate queries were executed.assertNoDuplicateQueries
: Assert that no duplicate queries were executed.assertHasSlowQueries
: Assert that slow queries were executed.assertNoSlowQueries
: Assert that no slow queries were executed.
Here's an example of using assertions in a test case:
Contributing
If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the GitHub repository.
License
The QueryWatcher package is open-source software licensed under the MIT license.