{"id":15159638,"url":"https://github.com/huubverbeek/query-watcher","last_synced_at":"2026-01-03T03:48:35.625Z","repository":{"id":166572902,"uuid":"642076547","full_name":"HuubVerbeek/query-watcher","owner":"HuubVerbeek","description":"A package to watch queries in your Laravel application -- including PHPUnit asserts. ","archived":false,"fork":false,"pushed_at":"2024-05-23T20:30:18.000Z","size":71,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T06:12:59.507Z","etag":null,"topics":["eloquent","feature-testing","laravel","phpunit","queries"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HuubVerbeek.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-17T19:11:29.000Z","updated_at":"2024-07-15T07:07:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"f5b5cb05-b443-436b-911d-990331156f27","html_url":"https://github.com/HuubVerbeek/query-watcher","commit_stats":null,"previous_names":["huubverbeek/querywatcher","huubverbeek/query-watcher"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuubVerbeek%2Fquery-watcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuubVerbeek%2Fquery-watcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuubVerbeek%2Fquery-watcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuubVerbeek%2Fquery-watcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HuubVerbeek","download_url":"https://codeload.github.com/HuubVerbeek/query-watcher/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830952,"owners_count":20354854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent","feature-testing","laravel","phpunit","queries"],"created_at":"2024-09-26T21:41:03.117Z","updated_at":"2026-01-03T03:48:35.561Z","avatar_url":"https://github.com/HuubVerbeek.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"### QueryWatcher\nQueryWatcher 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.\n\n#### Installation\nYou can install the QueryWatcher package via Composer by running the following command:\n\n`composer require huubverbeek/query-watcher`\n\n#### Requirements\nThis package requires php 8.1 or higher.\n\n#### Usage\nTo start watching queries, you can use the `watch` method provided by the `QueryWatcher` facade:\n\n```php\nuse HuubVerbeek\\QueryWatcher\\Facades\\QueryWatcher;\n\nQueryWatcher::watch();\n```\nThis will enable the query watcher and start collecting executed queries.\n\n#### All Queries\nTo retrieve all the queries you can use the `queries` method:\n\n```php\n$allQueries = QueryWatcher::queries();\n```\n\n#### Slow Queries\nTo retrieve the slow queries (queries that exceed a certain execution time), you can use the `slowQueries` method:\n\n```php\n$slowQueries = QueryWatcher::slowQueries();\n```\n\nYou can also set a custom threshold (the default is one second) for slow queries by using the `setSlowThreshold` method:\n\n```php\nQueryWatcher::setSlowThreshold(2.0); // Set slow threshold to 2 seconds\n\n```\n#### Duplicate Queries\nTo identify duplicate queries (queries with the same SQL statement and bindings), you can use the `duplicateQueries` method:\n\n```php\n$duplicateQueries = QueryWatcher::duplicateQueries();\n```\n\n#### Assertions\nThe 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.\n\n- `assertHasDuplicateQueries`: Assert that duplicate queries were executed.\n- `assertNoDuplicateQueries`: Assert that no duplicate queries were executed.\n- `assertHasSlowQueries`: Assert that slow queries were executed.\n- `assertNoSlowQueries`: Assert that no slow queries were executed.\n\nHere's an example of using assertions in a test case:\n\n```php\npublic function test_queries()\n{\n    QueryWatcher::watch();\n\n    // Code that executes queries\n\n    QueryWatcher::assertNoDuplicateQueries();\n    \n    QueryWatcher::assertNoSlowQueries();\n}\n```\n\n#### Contributing\nIf 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.\n\n#### License\nThe QueryWatcher package is open-source software licensed under the MIT license.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuubverbeek%2Fquery-watcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuubverbeek%2Fquery-watcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuubverbeek%2Fquery-watcher/lists"}