|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hoooklife\DynamodbPodm\Query; |
|
4
|
|
|
/** |
|
5
|
|
|
* Class DynamoDBBuilder |
|
6
|
|
|
* |
|
7
|
|
|
* @package BaoPham\DynamoDb\DynamoDb |
|
8
|
|
|
* |
|
9
|
|
|
* Methods are in the form of `set<key_name>`, where `<key_name>` |
|
10
|
|
|
* is the key name of the query body to be sent. |
|
11
|
|
|
* |
|
12
|
|
|
* For example, to build a query: |
|
13
|
|
|
* [ |
|
14
|
|
|
* 'AttributeDefinitions' => ..., |
|
15
|
|
|
* 'GlobalSecondaryIndexUpdates' => ... |
|
16
|
|
|
* 'TableName' => ... |
|
17
|
|
|
* ] |
|
18
|
|
|
* |
|
19
|
|
|
* Do: |
|
20
|
|
|
* |
|
21
|
|
|
* $query = $query->setAttributeDefinitions(...)->setGlobalSecondaryIndexUpdates(...)->setTableName(...); |
|
22
|
|
|
* |
|
23
|
|
|
* When ready: |
|
24
|
|
|
* |
|
25
|
|
|
* $query->prepare()->updateTable(); |
|
26
|
|
|
* |
|
27
|
|
|
* Common methods: |
|
28
|
|
|
* |
|
29
|
|
|
* @method DynamoDBBuilder setExpressionAttributeNames(array $mapping) |
|
30
|
|
|
* @method DynamoDBBuilder setExpressionAttributeValues(array $mapping) |
|
31
|
|
|
* @method DynamoDBBuilder setFilterExpression(string $expression) |
|
32
|
|
|
* @method DynamoDBBuilder setKeyConditionExpression(string $expression) |
|
33
|
|
|
* @method DynamoDBBuilder setProjectionExpression(string $expression) |
|
34
|
|
|
* @method DynamoDBBuilder setUpdateExpression(string $expression) |
|
35
|
|
|
* @method DynamoDBBuilder setAttributeUpdates(array $updates) |
|
36
|
|
|
* @method DynamoDBBuilder setConsistentRead(bool $consistent) |
|
37
|
|
|
* @method DynamoDBBuilder setScanIndexForward(bool $forward) |
|
38
|
|
|
* @method DynamoDBBuilder setExclusiveStartKey(mixed $key) |
|
39
|
|
|
* @method DynamoDBBuilder setReturnValues(string $type) |
|
40
|
|
|
* @method DynamoDBBuilder setRequestItems(array $items) |
|
41
|
|
|
* @method DynamoDBBuilder setTableName(string $table) |
|
42
|
|
|
* @method DynamoDBBuilder setIndexName(string $index) |
|
43
|
|
|
* @method DynamoDBBuilder setSelect(string $select) |
|
44
|
|
|
* @method DynamoDBBuilder setItem(array $item) |
|
45
|
|
|
* @method DynamoDBBuilder setKeys(array $keys) |
|
46
|
|
|
* @method DynamoDBBuilder setLimit(int $limit) |
|
47
|
|
|
* @method DynamoDBBuilder setKey(array $key) |
|
48
|
|
|
*/ |
|
49
|
|
|
class DynamoDBBuilder |
|
50
|
|
|
{ |
|
51
|
|
|
/** |
|
52
|
|
|
* Query body to be sent to AWS |
|
53
|
|
|
* |
|
54
|
|
|
* @var array |
|
55
|
|
|
*/ |
|
56
|
|
|
public $query = []; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param string $method |
|
60
|
|
|
* @param array $parameters |
|
61
|
|
|
* @return mixed |
|
62
|
|
|
*/ |
|
63
|
|
|
public function __call($method, $parameters) |
|
64
|
|
|
{ |
|
65
|
|
|
if (starts_with($method, 'set')) { |
|
|
|
|
|
|
66
|
|
|
$key = array_reverse(explode('set', $method, 2))[0]; |
|
67
|
|
|
$this->query[$key] = current($parameters); |
|
68
|
|
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
throw new BadMethodCallException(sprintf( |
|
|
|
|
|
|
71
|
|
|
'Method %s::%s does not exist.', |
|
72
|
|
|
static::class, |
|
73
|
|
|
$method |
|
74
|
|
|
)); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function exec() |
|
78
|
|
|
{ |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
} |