@@ -53,6 +53,13 @@ class Store
53
53
*/
54
54
private $ str_last_query = NULL ;
55
55
56
+ /**
57
+ * Named parameters for the last query
58
+ *
59
+ * @var array|null
60
+ */
61
+ private $ arr_last_params = NULL ;
62
+
56
63
/**
57
64
* The last result cursor
58
65
*
@@ -182,11 +189,13 @@ public function fetchByName($str_name)
182
189
* Fetch Entities based on a GQL query
183
190
*
184
191
* @param $str_query
192
+ * @param array|null $arr_params
185
193
* @return Entity[]
186
194
*/
187
- public function query ($ str_query )
195
+ public function query ($ str_query, $ arr_params = NULL )
188
196
{
189
197
$ this ->str_last_query = $ str_query ;
198
+ $ this ->arr_last_params = $ arr_params ;
190
199
$ this ->str_last_cursor = NULL ;
191
200
return $ this ;
192
201
}
@@ -195,33 +204,35 @@ public function query($str_query)
195
204
* Fetch ONE Entity based on a GQL query
196
205
*
197
206
* @param $str_query
207
+ * @param array|null $arr_params
198
208
* @return Entity
199
209
*/
200
- public function fetchOne ($ str_query = NULL )
210
+ public function fetchOne ($ str_query = NULL , $ arr_params = NULL )
201
211
{
202
212
if (NULL !== $ str_query ) {
203
- $ this ->query ($ str_query );
213
+ $ this ->query ($ str_query, $ arr_params );
204
214
}
205
215
$ arr_results = $ this ->obj_gateway
206
216
->withTransaction ($ this ->str_transaction_id )
207
- ->gql ($ this ->str_last_query . ' LIMIT 1 ' );
217
+ ->gql ($ this ->str_last_query . ' LIMIT 1 ' , $ this -> arr_last_params );
208
218
return $ this ->mapOneFromResults ($ arr_results );
209
219
}
210
220
211
221
/**
212
222
* Fetch Entities (optionally based on a GQL query)
213
223
*
214
224
* @param $str_query
225
+ * @param array|null $arr_params
215
226
* @return Entity[]
216
227
*/
217
- public function fetchAll ($ str_query = NULL )
228
+ public function fetchAll ($ str_query = NULL , $ arr_params = NULL )
218
229
{
219
230
if (NULL !== $ str_query ) {
220
- $ this ->query ($ str_query );
231
+ $ this ->query ($ str_query, $ arr_params );
221
232
}
222
233
$ arr_results = $ this ->obj_gateway
223
234
->withTransaction ($ this ->str_transaction_id )
224
- ->gql ($ this ->str_last_query );
235
+ ->gql ($ this ->str_last_query , $ this -> arr_last_params );
225
236
return $ this ->mapFromResults ($ arr_results );
226
237
}
227
238
@@ -235,7 +246,7 @@ public function fetchAll($str_query = NULL)
235
246
public function fetchPage ($ int_page_size , $ mix_offset = NULL )
236
247
{
237
248
$ str_offset = '' ;
238
- $ arr_params = [] ;
249
+ $ arr_params = ( array ) $ this -> arr_last_params ;
239
250
if (NULL !== $ mix_offset ) {
240
251
if (is_int ($ mix_offset )) {
241
252
$ str_offset = 'OFFSET @intOffset ' ;
@@ -248,6 +259,9 @@ public function fetchPage($int_page_size, $mix_offset = NULL)
248
259
$ str_offset = 'OFFSET @startCursor ' ;
249
260
$ arr_params ['startCursor ' ] = $ this ->str_last_cursor ;
250
261
}
262
+ if (empty ($ arr_params )) {
263
+ $ arr_params = NULL ;
264
+ }
251
265
$ arr_results = $ this ->obj_gateway
252
266
->withTransaction ($ this ->str_transaction_id )
253
267
->gql ($ this ->str_last_query . " LIMIT {$ int_page_size } {$ str_offset }" , $ arr_params );
0 commit comments