@@ -8,11 +8,10 @@ class ShardingQuery
8
8
{
9
9
10
10
/**
11
- * 数据库查询的回调
12
- * 回调必须返回数组类型
13
- * @var callable
11
+ * 查询闭包
12
+ * @var \Closure
14
13
*/
15
- public $ callback ;
14
+ public $ query ;
16
15
17
16
/**
18
17
* 数据表列表
@@ -28,29 +27,17 @@ class ShardingQuery
28
27
public $ field ;
29
28
30
29
/**
31
- * join
30
+ * innerJoin
32
31
* @var array
33
32
*/
34
33
public $ innerJoin ;
35
34
36
35
/**
37
- * join
36
+ * leftJoin
38
37
* @var array
39
38
*/
40
39
public $ leftJoin ;
41
40
42
- /**
43
- * join
44
- * @var array
45
- */
46
- public $ rightJoin ;
47
-
48
- /**
49
- * join
50
- * @var array
51
- */
52
- public $ fullJoin ;
53
-
54
41
/**
55
42
* 条件
56
43
* @var string
@@ -101,9 +88,9 @@ public function __construct(array $config)
101
88
{
102
89
foreach ($ config as $ key => $ value ) {
103
90
switch ($ key ) {
104
- case 'callback ' :
105
- if (!is_callable ($ value )) {
106
- throw new \RuntimeException ("'callback ' is not a callable type. " );
91
+ case 'query ' :
92
+ if (!($ value instanceof \Closure )) {
93
+ throw new \RuntimeException ("'query ' is not a closure type. " );
107
94
}
108
95
$ this ->$ key = $ value ;
109
96
break ;
@@ -131,18 +118,6 @@ public function __construct(array $config)
131
118
}
132
119
$ this ->$ key = $ value ;
133
120
break ;
134
- case 'rightJoin ' :
135
- if (!is_array ($ value )) {
136
- throw new \RuntimeException ("'rightJoin' is not a array type. " );
137
- }
138
- $ this ->$ key = $ value ;
139
- break ;
140
- case 'fullJoin ' :
141
- if (!is_array ($ value )) {
142
- throw new \RuntimeException ("'fullJoin' is not a array type. " );
143
- }
144
- $ this ->$ key = $ value ;
145
- break ;
146
121
case 'where ' :
147
122
if (!is_string ($ value )) {
148
123
throw new \RuntimeException ("'where' is not a string type. " );
@@ -187,7 +162,7 @@ public function select()
187
162
$ tmpSql = str_replace (static ::$ tableSymbol , $ tableName , $ sql );
188
163
$ tmpSql = "{$ tmpSql } LIMIT {$ item ['limit ' ]} OFFSET {$ item ['offset ' ]}" ;
189
164
$ this ->log (['sql ' => $ tmpSql ]);
190
- $ result = call_user_func ($ this ->callback , $ tmpSql );
165
+ $ result = call_user_func ($ this ->query , $ tmpSql );
191
166
$ this ->log (['resultCount ' => count ($ result )]);
192
167
$ data = array_merge ($ data , $ result );
193
168
}
@@ -210,8 +185,8 @@ protected function stats($table)
210
185
}
211
186
$ sql = str_replace (static ::$ tableSymbol , $ tableName , $ sql );
212
187
$ this ->log (['sql ' => $ sql ]);
213
- $ result = call_user_func ($ this ->callback , $ sql );
214
- $ first = array_pop ($ result );
188
+ $ result = call_user_func ($ this ->query , $ sql );
189
+ $ first = ( array ) array_pop ($ result );
215
190
$ count = array_pop ($ first );
216
191
$ this ->log (['result ' => $ count ]);
217
192
$ start = $ end ;
@@ -285,16 +260,6 @@ protected function sql()
285
260
$ sql .= " LEFT JOIN {$ item }" ;
286
261
}
287
262
}
288
- if (!empty ($ this ->rightJoin )) {
289
- foreach ($ this ->rightJoin as $ item ) {
290
- $ sql .= " RIGHT JOIN {$ item }" ;
291
- }
292
- }
293
- if (!empty ($ this ->fullJoin )) {
294
- foreach ($ this ->fullJoin as $ item ) {
295
- $ sql .= " FULL JOIN {$ item }" ;
296
- }
297
- }
298
263
if (!empty ($ this ->where )) {
299
264
$ sql .= " WHERE {$ this ->where }" ;
300
265
}
@@ -317,7 +282,7 @@ public function count()
317
282
}
318
283
319
284
/**
320
- * 记录日志
285
+ * 记录追踪数据
321
286
*/
322
287
protected function log ($ message )
323
288
{
0 commit comments