@@ -14,78 +14,65 @@ class Builder extends BaseBuilder
14
14
{
15
15
16
16
/**
17
- * DynamoDB params which expected to share across all subqueries.
17
+ * Name of the index.
18
+ * @var string|null
18
19
*/
19
- public $ dynamo_params = [
20
-
21
- /**
22
- * Name of the index.
23
- * @var string|null
24
- */
25
- 'index ' => null ,
26
-
27
- /**
28
- * The key.
29
- * @var array
30
- */
31
- 'key ' => [],
32
-
33
- /**
34
- * The item.
35
- * @var array
36
- */
37
- 'item ' => [],
38
-
39
- /**
40
- * The source of ProjectionExpression.
41
- * @var array
42
- */
43
- 'projections ' => [],
44
-
45
- /**
46
- * ConsistentRead option.
47
- * @var boolean
48
- */
49
- 'consistent_read ' => null ,
50
-
51
- /**
52
- * dry run option.
53
- * @var boolean
54
- */
55
- 'dry_run ' => false ,
56
-
57
- /**
58
- * The attribute name to place compiled wheres.
59
- * @var string
60
- */
61
- 'bind_wheres_to ' => 'FilterExpression ' ,
62
-
63
- /**
64
- * The ExpressionAttributes object.
65
- * @var Kitar\Dynamodb\Query\ExpressionAttributes
66
- */
67
- 'expression_attributes ' => null ,
68
- ];
20
+ public $ index = null ;
21
+
22
+ /**
23
+ * The key.
24
+ * @var array
25
+ */
26
+ public $ key = [];
27
+
28
+ /**
29
+ * The item.
30
+ * @var array
31
+ */
32
+ public $ item = [];
33
+
34
+ /**
35
+ * The source of ProjectionExpression.
36
+ * @var array
37
+ */
38
+ public $ projections = [];
39
+
40
+ /**
41
+ * ConsistentRead option.
42
+ * @var boolean|null
43
+ */
44
+ public $ consistent_read = null ;
45
+
46
+ /**
47
+ * dry run option.
48
+ * @var boolean
49
+ */
50
+ public $ dry_run = false ;
51
+
52
+ /**
53
+ * The attribute name to place compiled wheres.
54
+ * @var string
55
+ */
56
+ public $ bind_wheres_to = 'FilterExpression ' ;
57
+
58
+ /**
59
+ * The ExpressionAttributes object.
60
+ * @var Kitar\Dynamodb\Query\ExpressionAttributes
61
+ */
62
+ public $ expression_attributes = null ;
69
63
70
64
/**
71
65
* @inheritdoc
72
66
*/
73
- public function __construct (Connection $ connection , Grammar $ grammar , Processor $ processor , array $ dynamo_params = [] )
67
+ public function __construct (Connection $ connection , Grammar $ grammar , Processor $ processor , $ expression_attributes = null )
74
68
{
75
69
$ this ->connection = $ connection ;
76
70
77
71
$ this ->grammar = $ grammar ;
78
72
79
73
$ this ->processor = $ processor ;
80
74
81
- if (empty ($ dynamo_params ['expression_attributes ' ])) {
82
- $ dynamo_params ['expression_attributes ' ] = new ExpressionAttributes ;
83
- }
84
-
85
- $ this ->dynamo_params = array_merge (
86
- $ this ->dynamo_params ,
87
- $ dynamo_params
88
- );
75
+ $ this ->expression_attributes = $ expression_attributes ?? new ExpressionAttributes ;
89
76
}
90
77
91
78
/**
@@ -95,7 +82,7 @@ public function __construct(Connection $connection, Grammar $grammar, Processor
95
82
*/
96
83
public function index (string $ index )
97
84
{
98
- $ this ->dynamo_params [ ' index ' ] = $ index ;
85
+ $ this ->index = $ index ;
99
86
100
87
return $ this ;
101
88
}
@@ -107,7 +94,7 @@ public function index(string $index)
107
94
*/
108
95
public function key (array $ key )
109
96
{
110
- $ this ->dynamo_params [ ' key ' ] = $ key ;
97
+ $ this ->key = $ key ;
111
98
112
99
return $ this ;
113
100
}
@@ -119,7 +106,7 @@ public function key(array $key)
119
106
*/
120
107
public function consistentRead ($ active = true )
121
108
{
122
- $ this ->dynamo_params [ ' consistent_read ' ] = $ active ;
109
+ $ this ->consistent_read = $ active ;
123
110
124
111
return $ this ;
125
112
}
@@ -131,7 +118,7 @@ public function consistentRead($active = true)
131
118
*/
132
119
public function dryRun ($ active = true )
133
120
{
134
- $ this ->dynamo_params [ ' dry_run ' ] = $ active ;
121
+ $ this ->dry_run = $ active ;
135
122
136
123
return $ this ;
137
124
}
@@ -142,7 +129,7 @@ public function dryRun($active = true)
142
129
*/
143
130
public function whereAsFilter ()
144
131
{
145
- $ this ->dynamo_params [ ' bind_wheres_to ' ] = 'FilterExpression ' ;
132
+ $ this ->bind_wheres_to = 'FilterExpression ' ;
146
133
147
134
return $ this ;
148
135
}
@@ -153,7 +140,7 @@ public function whereAsFilter()
153
140
*/
154
141
public function whereAsCondition ()
155
142
{
156
- $ this ->dynamo_params [ ' bind_wheres_to ' ] = 'ConditionExpression ' ;
143
+ $ this ->bind_wheres_to = 'ConditionExpression ' ;
157
144
158
145
return $ this ;
159
146
}
@@ -164,7 +151,7 @@ public function whereAsCondition()
164
151
*/
165
152
public function whereAsKeyCondition ()
166
153
{
167
- $ this ->dynamo_params [ ' bind_wheres_to ' ] = 'KeyConditionExpression ' ;
154
+ $ this ->bind_wheres_to = 'KeyConditionExpression ' ;
168
155
169
156
return $ this ;
170
157
}
@@ -188,7 +175,7 @@ public function getItem($key = null)
188
175
*/
189
176
public function putItem ($ item )
190
177
{
191
- $ this ->dynamo_params [ ' item ' ] = $ item ;
178
+ $ this ->item = $ item ;
192
179
193
180
return $ this ->process ('putItem ' , null );
194
181
}
@@ -231,9 +218,9 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
231
218
{
232
219
// Convert column and value to ExpressionAttributes.
233
220
if (! $ column instanceof Closure) {
234
- $ column = $ this ->dynamo_params [ ' expression_attributes ' ] ->addName ($ column );
221
+ $ column = $ this ->expression_attributes ->addName ($ column );
235
222
if (! empty ($ value )) {
236
- $ value = $ this ->dynamo_params [ ' expression_attributes ' ] ->addValue ($ value );
223
+ $ value = $ this ->expression_attributes ->addValue ($ value );
237
224
}
238
225
}
239
226
@@ -276,7 +263,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
276
263
*/
277
264
public function newQuery ()
278
265
{
279
- return new static ($ this ->connection , $ this ->grammar , $ this ->processor , $ this ->dynamo_params );
266
+ return new static ($ this ->connection , $ this ->grammar , $ this ->processor , $ this ->expression_attributes );
280
267
}
281
268
282
269
/**
@@ -292,23 +279,23 @@ protected function process($query_method, $processor_method)
292
279
// These attributes needs to intaract with ExpressionAttributes during compile,
293
280
// so it need to run before compileExpressionAttributes.
294
281
$ params = array_merge (
295
- $ this ->grammar ->compileProjectionExpression ($ this ->columns , $ this ->dynamo_params [ ' expression_attributes ' ] ),
282
+ $ this ->grammar ->compileProjectionExpression ($ this ->columns , $ this ->expression_attributes ),
296
283
$ this ->grammar ->compileConditions ($ this ),
297
284
);
298
285
299
286
// Compile rest of attributes.
300
287
$ params = array_merge (
301
288
$ params ,
302
289
$ this ->grammar ->compileTableName ($ this ->from ),
303
- $ this ->grammar ->compileIndexName ($ this ->dynamo_params [ ' index ' ] ),
304
- $ this ->grammar ->compileKey ($ this ->dynamo_params [ ' key ' ] ),
305
- $ this ->grammar ->compileItem ($ this ->dynamo_params [ ' item ' ] ),
306
- $ this ->grammar ->compileConsistentRead ($ this ->dynamo_params [ ' consistent_read ' ] ),
307
- $ this ->grammar ->compileExpressionAttributes ($ this ->dynamo_params [ ' expression_attributes ' ] ),
290
+ $ this ->grammar ->compileIndexName ($ this ->index ),
291
+ $ this ->grammar ->compileKey ($ this ->key ),
292
+ $ this ->grammar ->compileItem ($ this ->item ),
293
+ $ this ->grammar ->compileConsistentRead ($ this ->consistent_read ),
294
+ $ this ->grammar ->compileExpressionAttributes ($ this ->expression_attributes ),
308
295
);
309
296
310
297
// Dry run.
311
- if ($ this ->dynamo_params [ ' dry_run ' ] ) {
298
+ if ($ this ->dry_run ) {
312
299
return [
313
300
'method ' => $ query_method ,
314
301
'params ' => $ params ,
0 commit comments