|
1 | 1 | # laravel-soar
|
2 | 2 |
|
3 |
| -> Assist laravel application sql optimization and rewriting. - 辅助 laravel 应用 sql 优化、重写。 |
| 3 | + |
4 | 4 |
|
5 |
| -[简体中文](README.md) | [ENGLISH](README-EN.md) |
| 5 | +> Sql optimizer、rewriter for laravel. - sql 优化器、重写器。 |
6 | 6 |
|
7 | 7 | [](https://github.com/guanguans/laravel-soar/actions)
|
8 | 8 | [](https://github.com/guanguans/laravel-soar/actions)
|
@@ -59,109 +59,16 @@ $app->register(\Guanguans\LaravelSoar\SoarServiceProvider::class);
|
59 | 59 |
|
60 | 60 | ## Usage
|
61 | 61 |
|
62 |
| -### Generate sql scoring report example |
| 62 | +### Automatically monitor output sql score |
63 | 63 |
|
64 |
| -```php |
65 |
| -use App\Models\Member; |
66 |
| - |
67 |
| -Member::query() |
68 |
| - ->select([ |
69 |
| - 'id', |
70 |
| - 'nickname', |
71 |
| - ]) |
72 |
| - ->where('id', 100) |
73 |
| - // ->toSoarScore() // Generate sql score report. |
74 |
| - // ->dumpSoarScore() // Print sql scoring report. |
75 |
| - ->ddSoarScore() // Print the sql score report and exit the application. |
76 |
| -; |
77 |
| -``` |
78 |
| - |
79 |
| - |
80 |
| - |
81 |
| -```php |
82 |
| -// Query builder usage example. |
83 |
| -DB::table('yb_member') |
84 |
| - ->select('*') |
85 |
| - ->join('yb_member_account as yb_member_account', 'yb_member_account.member_id', '=', 'yb_member.id') |
86 |
| - ->whereRaw('1 <> 1') |
87 |
| - ->where('yb_member.nickname', 'like', 'admin') |
88 |
| - ->where('yb_member.username', 'like', '%admin%') |
89 |
| - ->whereRaw("substring(yb_member.username, 1, 5) = 'admin'") |
90 |
| - ->whereIn('yb_member.id', [110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120]) |
91 |
| - ->orWhereNotNull('yb_member.realname') |
92 |
| - ->groupByRaw("yb_member.status, '100'") |
93 |
| - ->having('yb_member.id', '>', '100') |
94 |
| - ->orderByRaw('RAND()') |
95 |
| - // ->toSoarScore() // Generate sql score report. |
96 |
| - // ->dumpSoarScore() // Print sql scoring report. |
97 |
| - ->ddSoarScore() // Print the sql score report and exit the application. |
98 |
| -; |
99 |
| -``` |
100 |
| - |
101 |
| - |
102 |
| - |
103 |
| -### Generate an explain information interpretation report example |
104 |
| - |
105 |
| -```php |
106 |
| -// Query builder usage example. |
107 |
| -DB::table('yb_member') |
108 |
| - ->select('*') |
109 |
| - ->join('yb_member_account as yb_member_account', 'yb_member_account.member_id', '=', 'yb_member.id') |
110 |
| - ->whereRaw('1 <> 1') |
111 |
| - ->where('yb_member.nickname', 'like', 'admin') |
112 |
| - ->where('yb_member.username', 'like', '%admin%') |
113 |
| - ->whereRaw("substring(yb_member.username, 1, 5) = 'admin'") |
114 |
| - ->whereIn('yb_member.id', [110, 120]) |
115 |
| - ->orWhereNotNull('yb_member.realname') |
116 |
| - ->groupByRaw("yb_member.status, '100'") |
117 |
| - ->having('yb_member.id', '>', '100') |
118 |
| - ->orderByRaw('RAND()') |
119 |
| - // ->toSoarHtmlExplain() // Generate explain information interpretation report. |
120 |
| - // ->dumpSoarHtmlExplain() // Print explain information interpretation report. |
121 |
| - ->ddSoarHtmlExplain() // Print the explain information interpretation report, and exit the application. |
122 |
| -; |
123 |
| -``` |
124 |
| - |
125 |
| - |
126 |
| - |
127 |
| -### Beautify sql statemen |
128 |
| - |
129 |
| -```php |
130 |
| -// Query builder usage example. |
131 |
| -DB::table('yb_member') |
132 |
| - ->select('*') |
133 |
| - ->join('yb_member_account as yb_member_account', 'yb_member_account.member_id', '=', 'yb_member.id') |
134 |
| - ->whereRaw('1 <> 1') |
135 |
| - ->where('yb_member.nickname', 'like', 'admin') |
136 |
| - ->where('yb_member.username', 'like', '%admin%') |
137 |
| - ->whereRaw("substring(yb_member.username, 1, 5) = 'admin'") |
138 |
| - ->whereIn('yb_member.id', [110, 120]) |
139 |
| - ->orWhereNotNull('yb_member.realname') |
140 |
| - ->groupByRaw("yb_member.status, '100'") |
141 |
| - ->having('yb_member.id', '>', '100') |
142 |
| - ->orderByRaw('RAND()') |
143 |
| - // ->toSoarPretty() // Generate beautified sql. |
144 |
| - // ->dumpSoarPretty() // Print beautified sql. |
145 |
| - ->dumpSoarPretty() // Print the beautified sql, and exit the application. |
146 |
| -; |
147 |
| -``` |
148 |
| - |
149 |
| - |
| 64 | + |
150 | 65 |
|
151 |
| -### Facade usage examples |
| 66 | +### Example of use |
152 | 67 |
|
153 | 68 | ```php
|
154 |
| -$sql = Member::query()->select(['id', 'nickname'])->where('id', 100)->toRawSql(); |
155 |
| - |
156 |
| -\Soar::score($sql); // Generate sql score report. |
157 |
| -\Soar::mdExplain($sql); // Generate explain information interpretation report in markdown format. |
158 |
| -\Soar::htmlExplain($sql); // Generate Explain information interpretation report in html format. |
159 |
| -\Soar::syntaxCheck($sql); // SQL syntax check. |
160 |
| -\Soar::fingerPrint($sql); // Generate sql fingerprint. |
161 |
| -\Soar::pretty($sql); // Beautify sql. |
162 |
| -\Soar::md2html($sql); // Convert markdown format content to html format content. |
163 |
| -\Soar::help($sql); // Output soar help command content. |
164 |
| -\Soar::exec($command); // Execute any soar command. |
| 69 | +$soar = app('soar'); // get soar instance |
| 70 | +User::query()->ddSoarJsonScore() // Convenience query method to output scoring report |
| 71 | +\Soar::jsonScore(User::query()->toRawSql()); // soar facade generates scoring report |
165 | 72 | ```
|
166 | 73 |
|
167 | 74 | ## Testing
|
|
0 commit comments