guanguans / laravel-dump-sql
laravel 中轻松容易的输出完整的 SQL 语句。 - Easy output of complete SQL statements for laravel framework.
Fund package maintenance!
Patreon
www.guanguans.cn/images/wechat.jpeg
Installs: 26 819
Dependents: 0
Suggesters: 0
Security: 0
Stars: 36
Watchers: 2
Forks: 5
Open Issues: 1
Type:laravel
Requires
- php: >=7.3
- illuminate/console: ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
- illuminate/database: ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
- illuminate/http: ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
- illuminate/log: ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
- illuminate/support: ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
- symfony/var-dumper: ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.8
- ergebnis/composer-normalize: ^2.20
- friendsofphp/php-cs-fixer: ^3.4
- guanguans/ai-commit: dev-main
- guanguans/monorepo-builder-worker: ^1.4
- laravel/legacy-factories: ^1.4
- mockery/mockery: ^1.6
- orchestra/testbench: ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0
- phpunit/phpunit: ^9.6 || ^10.0 || ^11.0
- rector/rector: ^1.0
- vimeo/psalm: ^4.30 || ^5.0
- dev-master
- 2.5.0
- 2.4.0
- v2.3.0
- v2.2.1
- v2.2.0
- v2.1.0
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- 1.x-dev
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/composer/brainmaestro/composer-git-hooks-tw-3.0
- dev-issue-19-laravel5_8版本下能安装扩展么
This package is auto-updated.
Last update: 2024-12-09 22:10:50 UTC
README
Assist laravel application to obtain complete sql statement. - 辅助 laravel 应用获取完整的 sql 语句。
The sql statement obtained by the query construction method in laravel is not bound to the conditional parameters, similar to
select * from users where id= ?
. This expansion pack can help you get a complete sql statement. - laravel 中查询构造方法得到的 sql 语句没有绑定条件参数,类似于select * from users where id= ?
。这个扩展包可辅助你获取完整的 sql 语句。
功能
- 添加获取 sql 语句的查询构建便捷方法(
toRawSql
、dumpSql
、ddSql
、logListenedSql
、dumpListenedSql
、ddListenedSql
) - 添加监控 sql 语句的服务命令
环境要求
- laravel || lumen >= 6.10
安装
$ composer require guanguans/laravel-dump-sql -v
lumen 中配置(laravel 中请忽略)
将下面代码添加到 bootstrap/app.php
文件中的 Register Service Providers
部分
$app->register(\Guanguans\LaravelDumpSql\ServiceProvider::class);
使用
监控 sql 语句的服务的使用
$ php artisan server:dump-sql
获取 sql 语句的查询构建便捷方法的使用
安装配置完毕后数据库查询构造方法会新增以下几个方法:
- toRawSql() - 获取完整的 sql
- dumpSql() - 打印完整的 sql
- ddSql() - 打印完整的 sql 并且退出
- logListenedSql() - 记录被监听到的 sql
- dumpListenedSql() - 打印被监听到的 sql
- ddListenedSql() - 打印被监听到的 sql 并且退出
toRawSql() - 获取完整的 sql
$sql = User::query()->where('id', 1)->toRawSql(); dd($sql);
"select * from `xb_users` where `id` = 1"
dumpSql() - 打印完整的 sql
User::query()->where('id', 1)->dumpSql(); User::query()->where('id', 2)->dumpSql();
"select * from `xb_users` where `id` = 1" "select * from `xb_users` where `id` = 2"
ddSql() - 打印完整的 sql 并且退出
User::query()->where('id', 1)->ddSql(); User::query()->where('id', 2)->ddSql();
"select * from `xb_users` where `id` = 1"
logListenedSql() - 记录被监听到的 sql
User::query()->where('id', 1)->logListenedSql()->first(); User::query()->where('id', 2)->first();
# 日志中 [Laravel] [39.97ms] select * from `xb_users` where `id` = '1' limit 1 | GET: / [Laravel] [39.93ms] select * from `xb_users` where `id` = '2' limit 1 | GET: /
dumpListenedSql() - 打印被监听到的 sql
User::query()->where('id', 1)->dumpListenedSql()->first(); User::query()->where('id', 2)->first();
[Laravel] [39.97ms] select * from `xb_users` where `id` = '1' limit 1 | GET: / [Laravel] [39.93ms] select * from `xb_users` where `id` = '2' limit 1 | GET: /
ddListenedSql() - 打印被监听到的 sql 并且退出
User::query()->where('id', 1)->ddListenedSql()->first(); User::query()->where('id', 2)->first();
[Laravel] [39.97ms] select * from `xb_users` where `id` = '1' limit 1 | GET: /
安全漏洞
请查看我们的安全政策了解如何报告安全漏洞。
贡献者
协议
MIT 许可证(MIT)。有关更多信息,请参见协议文件。