|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Guillermoandrae\Db\DynamoDb; |
|
4
|
|
|
|
|
5
|
|
|
abstract class AbstractSearchRequest extends AbstractFilterExpressionAwareRequest |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var string The name of the index. |
|
9
|
|
|
*/ |
|
10
|
|
|
const SELECT_ALL_ATTRIBUTES = 'ALL_ATTRIBUTES'; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var string The name of the index. |
|
14
|
|
|
*/ |
|
15
|
|
|
const SELECT_ALL_PROJECTED_ATTRIBUTES = 'ALL_PROJECTED_ATTRIBUTES'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var string The name of the index. |
|
19
|
|
|
*/ |
|
20
|
|
|
const SELECT_SPECIFIC_ATTRIBUTES = 'SPECIFIC_ATTRIBUTES'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string The name of the index. |
|
24
|
|
|
*/ |
|
25
|
|
|
const SELECT_COUNT = 'COUNT'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var boolean Whether or not to scan forward. |
|
29
|
|
|
*/ |
|
30
|
|
|
private $scanIndexForward = false; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var boolean Whether or not the read should be consistent. |
|
34
|
|
|
*/ |
|
35
|
|
|
private $consistentRead = false; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string The name of a secondary index to request against. |
|
39
|
|
|
*/ |
|
40
|
|
|
private $indexName = ''; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var string The attributes to be returned in the result. |
|
44
|
|
|
*/ |
|
45
|
|
|
private $select = ''; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var string The attributes to retrieve from the specified table or index. |
|
49
|
|
|
*/ |
|
50
|
|
|
private $projectionExpression = ''; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Registers the ScanIndexForward value with this object. |
|
54
|
|
|
* |
|
55
|
|
|
* @param boolean $scanIndexForward Whether or not to scan forward. |
|
56
|
|
|
* @return AbstractSearchRequest This object. |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function setScanIndexForward(bool $scanIndexForward): AbstractSearchRequest |
|
59
|
|
|
{ |
|
60
|
1 |
|
$this->scanIndexForward = $scanIndexForward; |
|
61
|
1 |
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Registers the ConsistentRead value with this object. |
|
66
|
|
|
* |
|
67
|
|
|
* @param boolean $consistentRead Whether or not the read should be consistent. |
|
68
|
|
|
* @return AbstractSearchRequest This object. |
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function setConsistentRead(bool $consistentRead): AbstractSearchRequest |
|
71
|
|
|
{ |
|
72
|
1 |
|
$this->consistentRead = $consistentRead; |
|
73
|
1 |
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Registers the name of the secondary index to use. |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $indexName The name of the secondary index to use. |
|
80
|
|
|
* @return AbstractSearchRequest This object. |
|
81
|
|
|
*/ |
|
82
|
1 |
|
public function setIndexName(string $indexName): AbstractSearchRequest |
|
83
|
|
|
{ |
|
84
|
1 |
|
$this->indexName = $indexName; |
|
85
|
1 |
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Registers the attributes to be return in the result. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $select The attributes to be return in the result. |
|
92
|
|
|
* @return AbstractSearchRequest This object. |
|
93
|
|
|
*/ |
|
94
|
1 |
|
public function setSelect(string $select): AbstractSearchRequest |
|
95
|
|
|
{ |
|
96
|
1 |
|
$this->select = $select; |
|
97
|
1 |
|
return $this; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Registers the attributes to retrieve from the specified table or index. |
|
102
|
|
|
* |
|
103
|
|
|
* @param string $projectionExpression The attributes to retrieve from the specified table or index. |
|
104
|
|
|
* @return AbstractSearchRequest This object. |
|
105
|
|
|
*/ |
|
106
|
1 |
|
public function setProjectionExpression(string $projectionExpression): AbstractSearchRequest |
|
107
|
|
|
{ |
|
108
|
1 |
|
$this->projectionExpression = $projectionExpression; |
|
109
|
1 |
|
return $this; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* {@inheritDoc} |
|
114
|
|
|
*/ |
|
115
|
12 |
|
public function get(): array |
|
116
|
|
|
{ |
|
117
|
12 |
|
$query = parent::get(); |
|
118
|
12 |
|
$query['ScanIndexForward'] = $this->scanIndexForward; |
|
119
|
12 |
|
$query['ConsistentRead'] = $this->consistentRead; |
|
120
|
12 |
|
if (!empty($this->indexName)) { |
|
121
|
1 |
|
$query['IndexName'] = $this->indexName; |
|
122
|
|
|
} |
|
123
|
12 |
|
if (!empty($this->select)) { |
|
124
|
1 |
|
$query['Select'] = $this->select; |
|
125
|
|
|
} |
|
126
|
12 |
|
if (!empty($this->projectionExpression)) { |
|
127
|
1 |
|
$query['ProjectionExpression'] = $this->projectionExpression; |
|
128
|
|
|
} |
|
129
|
12 |
|
return $query; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|