# soar-php **Repository Path**: ygit-can/soar-php ## Basic Information - **Project Name**: soar-php - **Description**: SQL optimizer and rewriter php extension package - SQL优化器和重写器PHP扩展包、方便框架中SQL调优。 - **Primary Language**: PHP - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 8 - **Created**: 2020-11-13 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
SQL statement optimizer and rewriter
> **[soar-php](https://github.com/guanguans/soar-php)** is a PHP extension package based on Xiaomi's open source [soar](https://github.com/XiaoMi/soar) development. It is a SQL statement tuning development tool for PHP engineers. [](https://travis-ci.org/guanguans/soar-php) [](https://scrutinizer-ci.com/g/guanguans/soar-php/build-status/master) [](https://scrutinizer-ci.com/g/guanguans/soar-php/?branch=master) [](https://codecov.io/gh/guanguans/soar-php) [](https://github.styleci.io/repos/178793017) [](https://packagist.org/packages/guanguans/soar-php) [](https://packagist.org/packages/guanguans/soar-php) [](https://packagist.org/packages/guanguans/soar-php) ## Requirements * PHP >= 7.1 * ext-pdo ## Used in the framework - [x] Laravel - [laravel-web-soar](https://github.com/huangdijia/laravel-web-soar) - [x] ThinkPHP - [think-soar](https://github.com/guanguans/think-soar) - [x] Hyperf - [hyperf-soar](https://github.com/wilbur-oo/hyperf-soar) - [ ] Yii2 - [ ] Symfony - [ ] Slim ## Installation ``` shell $ composer require guanguans/soar-php --dev ``` ## Usage ### Download [XiaoMi](https://github.com/XiaoMi/) open source SQL optimizer [soar](https://github.com/XiaoMi/soar/releases), please refer to [soar install](https://github.com/XiaoMi/soar/blob/master/doc/install.md) for more detailed installation ``` bash # macOS $ wget https://github.com/XiaoMi/soar/releases/download/0.11.0/soar.darwin-amd64 # linux $ wget https://github.com/XiaoMi/soar/releases/download/0.11.0/soar.linux-amd64 # windows $ wget https://github.com/XiaoMi/soar/releases/download/0.11.0/soar.windows-amd64 # Download with other commands or downloader ``` ### Initial configuration, please refer to [soar config](https://github.com/XiaoMi/soar/blob/master/doc/config.md) for more detailed configuration #### 一、The runtime initialization configuration ``` php '/Users/yaozm/Documents/wwwroot/soar-php/soar.darwin-amd64', // Test environment configuration '-test-dsn' => [ 'host' => '127.0.0.1', 'port' => '3306', 'dbname' => 'database', 'username' => 'root', 'password' => '123456', ], // log output file '-log-output' => './soar.log', // Report output format: default markdown [markdown, html, json] '-report-type' => 'html', ]; $soar = new Soar($config); ``` #### 二、Configuration file initial config Create file `.soar.dist` or `.soar` in the `vendor` same directory , content reference [.soar.example](.soar.example), for example: ``` php '/Users/yaozm/Documents/wwwroot/soar-php/soar.darwin-amd64', // Test environment configuration '-test-dsn' => [ 'host' => '127.0.0.1', 'port' => '3306', 'dbname' => 'database', 'username' => 'root', 'password' => '123456', ], // log output file '-log-output' => './soar.log', // Report output format: default markdown [markdown, html, json] '-report-type' => 'html', ]; ``` Then initialize ``` php `.soar` > `.soar.dist` ### SQL score **Method call:** ``` php $sql ="SELECT * FROM `fa_user` `user` LEFT JOIN `fa_user_group` `group` ON `user`.`group_id`=`group`.`id`;"; echo $soar->score($sql); ``` **Output results:**  ### explain information **Method call:** ``` php $sql = "SELECT * FROM `fa_auth_group_access` `aga` LEFT JOIN `fa_auth_group` `ag` ON `aga`.`group_id`=`ag`.`id`;"; // Output html format echo $soar->htmlExplain($sql); // Output markdown format echo $soar->mdExplain($sql); // Output html format echo $soar->explain($sql, 'html'); // Output markdown format echo $soar->explain($sql, 'md'); ``` **Output results:**  ### Grammar check **Method call:** ``` php $sql = 'selec * from fa_user'; echo $soar->syntaxCheck($sql); ``` **Output results:** ``` sql At SQL 1 : line 1 column 5 near "selec * from fa_user" (total length 20) ``` ### SQL fingerprint **Method call:** ``` php $sql = 'select * from fa_user where id=1'; echo $soar->fingerPrint($sql); ``` **Output results:** ``` sql select * from fa_user where id = ? ``` ### SQL pretty **Method call:** ``` php $sql = 'select * from fa_user where id=1'; var_dump($soar->pretty($sql)); ``` **Output results:** ``` sql SELECT * FROM fa_user WHERE id = 1; ``` ### Markdown to html **Method call:** ``` php echo $soar->md2html("## this is a test"); ``` **Output results:** ``` html ...kamly 🐛 |
Leslie Lau 🐛 |
D.J.Hwang 🤔 |