Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
guanguans committed Apr 13, 2022
1 parent 6813a36 commit 43a7723
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 203 deletions.
109 changes: 8 additions & 101 deletions README-EN.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# laravel-soar

> Assist laravel application sql optimization and rewriting. - 辅助 laravel 应用 sql 优化、重写。
![](docs/debug-bar.png)

[简体中文](README.md) | [ENGLISH](README-EN.md)
> Sql optimizer、rewriter for laravel. - sql 优化器、重写器。
[![Tests](https://github.com/guanguans/laravel-soar/workflows/Tests/badge.svg)](https://github.com/guanguans/laravel-soar/actions)
[![Check & fix styling](https://github.com/guanguans/laravel-soar/workflows/Check%20&%20fix%20styling/badge.svg)](https://github.com/guanguans/laravel-soar/actions)
Expand Down Expand Up @@ -59,109 +59,16 @@ $app->register(\Guanguans\LaravelSoar\SoarServiceProvider::class);

## Usage

### Generate sql scoring report example
### Automatically monitor output sql score

```php
use App\Models\Member;

Member::query()
->select([
'id',
'nickname',
])
->where('id', 100)
// ->toSoarScore() // Generate sql score report.
// ->dumpSoarScore() // Print sql scoring report.
->ddSoarScore() // Print the sql score report and exit the application.
;
```

![high-score](./docs/high-score.png)

```php
// Query builder usage example.
DB::table('yb_member')
->select('*')
->join('yb_member_account as yb_member_account', 'yb_member_account.member_id', '=', 'yb_member.id')
->whereRaw('1 <> 1')
->where('yb_member.nickname', 'like', 'admin')
->where('yb_member.username', 'like', '%admin%')
->whereRaw("substring(yb_member.username, 1, 5) = 'admin'")
->whereIn('yb_member.id', [110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120])
->orWhereNotNull('yb_member.realname')
->groupByRaw("yb_member.status, '100'")
->having('yb_member.id', '>', '100')
->orderByRaw('RAND()')
// ->toSoarScore() // Generate sql score report.
// ->dumpSoarScore() // Print sql scoring report.
->ddSoarScore() // Print the sql score report and exit the application.
;
```

![low-score](./docs/low-score.png)

### Generate an explain information interpretation report example

```php
// Query builder usage example.
DB::table('yb_member')
->select('*')
->join('yb_member_account as yb_member_account', 'yb_member_account.member_id', '=', 'yb_member.id')
->whereRaw('1 <> 1')
->where('yb_member.nickname', 'like', 'admin')
->where('yb_member.username', 'like', '%admin%')
->whereRaw("substring(yb_member.username, 1, 5) = 'admin'")
->whereIn('yb_member.id', [110, 120])
->orWhereNotNull('yb_member.realname')
->groupByRaw("yb_member.status, '100'")
->having('yb_member.id', '>', '100')
->orderByRaw('RAND()')
// ->toSoarHtmlExplain() // Generate explain information interpretation report.
// ->dumpSoarHtmlExplain() // Print explain information interpretation report.
->ddSoarHtmlExplain() // Print the explain information interpretation report, and exit the application.
;
```

![explain](./docs/explain.png)

### Beautify sql statemen

```php
// Query builder usage example.
DB::table('yb_member')
->select('*')
->join('yb_member_account as yb_member_account', 'yb_member_account.member_id', '=', 'yb_member.id')
->whereRaw('1 <> 1')
->where('yb_member.nickname', 'like', 'admin')
->where('yb_member.username', 'like', '%admin%')
->whereRaw("substring(yb_member.username, 1, 5) = 'admin'")
->whereIn('yb_member.id', [110, 120])
->orWhereNotNull('yb_member.realname')
->groupByRaw("yb_member.status, '100'")
->having('yb_member.id', '>', '100')
->orderByRaw('RAND()')
// ->toSoarPretty() // Generate beautified sql.
// ->dumpSoarPretty() // Print beautified sql.
->dumpSoarPretty() // Print the beautified sql, and exit the application.
;
```

![pretty](./docs/pretty.png)
![](docs/debug-bar.png)

### Facade usage examples
### Example of use

```php
$sql = Member::query()->select(['id', 'nickname'])->where('id', 100)->toRawSql();

\Soar::score($sql); // Generate sql score report.
\Soar::mdExplain($sql); // Generate explain information interpretation report in markdown format.
\Soar::htmlExplain($sql); // Generate Explain information interpretation report in html format.
\Soar::syntaxCheck($sql); // SQL syntax check.
\Soar::fingerPrint($sql); // Generate sql fingerprint.
\Soar::pretty($sql); // Beautify sql.
\Soar::md2html($sql); // Convert markdown format content to html format content.
\Soar::help($sql); // Output soar help command content.
\Soar::exec($command); // Execute any soar command.
$soar = app('soar'); // get soar instance
User::query()->ddSoarJsonScore() // Convenience query method to output scoring report
\Soar::jsonScore(User::query()->toRawSql()); // soar facade generates scoring report
```

## Testing
Expand Down
111 changes: 10 additions & 101 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# laravel-soar

> Assist laravel application sql optimization and rewriting. - 辅助 laravel 应用 sql 优化、重写。
![](docs/debug-bar.png)

> Sql optimizer、rewriter for laravel. - sql 优化器、重写器。
[简体中文](README.md) | [ENGLISH](README-EN.md)

Expand Down Expand Up @@ -31,7 +33,7 @@

## 环境要求

* laravel >= 5.5
* laravel >= 6.10

## 安装

Expand Down Expand Up @@ -59,109 +61,16 @@ $app->register(\Guanguans\LaravelSoar\SoarServiceProvider::class);

## 使用

### 生成 sql 评分报告示例

```php
use App\Models\Member;

Member::query()
->select([
'id',
'nickname',
])
->where('id', 100)
// ->toSoarScore() // 生成 sql 评分报告
// ->dumpSoarScore() // 打印 sql 评分报告
->ddSoarScore() // 打印 sql 评分报告,并且退出应用程序。
;
```

![high-score](./docs/high-score.png)

```php
// 查询构建器使用示例
DB::table('yb_member')
->select('*')
->join('yb_member_account as yb_member_account', 'yb_member_account.member_id', '=', 'yb_member.id')
->whereRaw('1 <> 1')
->where('yb_member.nickname', 'like', 'admin')
->where('yb_member.username', 'like', '%admin%')
->whereRaw("substring(yb_member.username, 1, 5) = 'admin'")
->whereIn('yb_member.id', [110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120])
->orWhereNotNull('yb_member.realname')
->groupByRaw("yb_member.status, '100'")
->having('yb_member.id', '>', '100')
->orderByRaw('RAND()')
// ->toSoarScore() // 生成 sql 评分报告
// ->dumpSoarScore() // 打印 sql 评分报告
->ddSoarScore() // 打印 sql 评分报告,并且退出应用程序。
;
```

![low-score](./docs/low-score.png)

### 生成 explain 信息解读报告示例

```php
// 查询构建器使用示例
DB::table('yb_member')
->select('*')
->join('yb_member_account as yb_member_account', 'yb_member_account.member_id', '=', 'yb_member.id')
->whereRaw('1 <> 1')
->where('yb_member.nickname', 'like', 'admin')
->where('yb_member.username', 'like', '%admin%')
->whereRaw("substring(yb_member.username, 1, 5) = 'admin'")
->whereIn('yb_member.id', [110, 120])
->orWhereNotNull('yb_member.realname')
->groupByRaw("yb_member.status, '100'")
->having('yb_member.id', '>', '100')
->orderByRaw('RAND()')
// ->toSoarHtmlExplain() // 生成 explain 信息解读报告
// ->dumpSoarHtmlExplain() // 打印 explain 信息解读报告
->ddSoarHtmlExplain() // 打印 explain 信息解读报告,并且退出应用程序。
;
```

![explain](./docs/explain.png)

### 美化 sql 语句

```php
// 查询构建器使用示例
DB::table('yb_member')
->select('*')
->join('yb_member_account as yb_member_account', 'yb_member_account.member_id', '=', 'yb_member.id')
->whereRaw('1 <> 1')
->where('yb_member.nickname', 'like', 'admin')
->where('yb_member.username', 'like', '%admin%')
->whereRaw("substring(yb_member.username, 1, 5) = 'admin'")
->whereIn('yb_member.id', [110, 120])
->orWhereNotNull('yb_member.realname')
->groupByRaw("yb_member.status, '100'")
->having('yb_member.id', '>', '100')
->orderByRaw('RAND()')
// ->toSoarPretty() // 生成美化后的 sql
// ->dumpSoarPretty() // 打印美化后的 sql
->dumpSoarPretty() // 打印美化后的 sql,并且退出应用程序。
;
```
### 自动监控输出 sql 评分

![pretty](./docs/pretty.png)
![](docs/debug-bar.png)

### 门面使用示例
### 使用示例

```php
$sql = Member::query()->select(['id', 'nickname'])->where('id', 100)->toRawSql();

\Soar::score($sql); // 生成 sql 评分报告
\Soar::mdExplain($sql); // 生成 markdown 格式的 explain 信息解读报告
\Soar::htmlExplain($sql); // 生成 html 格式的 Explain 信息解读报告
\Soar::syntaxCheck($sql); // sql 语法检查
\Soar::fingerPrint($sql); // 生成 sql 指纹
\Soar::pretty($sql); // 美化 sql
\Soar::md2html($sql); // 将 markdown 格式内容转化为 html 格式内容
\Soar::help($sql); // 输出 soar 帮助命令内容
\Soar::exec($command); // 执行任意 soar 命令
$soar = app('soar'); // 获取 soar 实例
User::query()->ddSoarJsonScore() // 便捷查询器方法输出评分报告
\Soar::jsonScore(User::query()->toRawSql()); // soar 门面生成评分报告
```

## 测试
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "guanguans/laravel-soar",
"description": "Assist laravel application sql optimization and rewriting. - 辅助 laravel 应用 sql 优化、重写",
"description": "Sql optimizer、rewriter for laravel. - sql 优化器、重写器",
"license": "MIT",
"type": "laravel",
"keywords": [
Expand Down
Binary file added docs/debug-bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 43a7723

Please sign in to comment.